protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
Bindgrid();
}//编辑按键下的取消代码。将EditIndex=-1,然后在绑定数据库。
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex][0].ToString();
DeleteGridView(id);
Bindgrid();
}// id = GridView1.DataKeys[e.RowIndex][0].ToString();获得girdwiew中表的主键,作为删除数据的标识。DeleteGirdView()为自己写的删除函数 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
Bindgrid();
}//获取当前编辑状态
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex][0].ToString();
string uid = ((TextBox )GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string upassword = ((TextBox )GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
string upower = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
UpdataGridView(id, uid, upassword, upower);
GridView1.EditIndex = -1;
Bindgrid();
}//获得GridView中选中行的各列数据,用UpdataGridView()更新数据
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Bindgrid();
}//换页的时候获取当前编辑页 public void UpdataGridView(string id,string uid,string upassword,string upower)
{
SqlConnection con=new SqlConnection ("server=localhost;database=YGXXXT;uid=sa;password=00");
string sql="update Users set ID='"+id+"',UID='"+uid+"',UPassword='"+upassword+"',UPower='"+upower+"'";
SqlCommand cmd=new SqlCommand (sql,con );
con.Open ();
cmd.ExecuteNonQuery ();
con.Close(); }//更新数据库数据,注意sql语句里的'"+id+'"不要弄错格式~~~
public void DeleteGridView(string id)
{
SqlConnection con = new SqlConnection("server=localhost;database=YGXXXT;uid=sa;password=00");
string sql = "delete Users where ID='"+id +"'";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}//删除数据库数据

终于可以怎么控制GridView里面的操作了,相当开心~接下了就是看看怎么用母板。然后就可以深入实践项目~

在网站功能模块划分上要注意隔离性~慢慢来~

给力的。。。

GridView 编辑,更新,删除 等操作~~的更多相关文章

  1. GridView 编辑、删除 、分页

    类似代码都差不多,记录一下,便于以后查看使用. 前台页面: <asp:GridView ID="gdvList" runat="server" AutoG ...

  2. repeater做成gridview【更新删除编辑等】

    原文发布时间为:2009-06-14 -- 来源于本人的百度文章 [由搬家工具导入] 不多说,不会说。。看我做的范例。。。 http://download.csdn.net/source/138556 ...

  3. Asp.Net:GridView 编辑、删除、自定义分页以后备用

    页面 GridView 绑定:在中,有 <asp:BoundField/>和 <asp:TemplateField><ItemTemplate>嵌套服务器控件 &l ...

  4. Android Sqlite数据库执行插入查询更新删除的操作对比

    下面是在Android4.0上,利用Sqlite数据库的insert,query,update,delete函数以及execSql,rawQuery函数执行插入,查询,更新,删除操作花费时间的对比结果 ...

  5. C# 实现对PPT插入、编辑、删除表格

    现代学习和办公当中,经常会接触到对表格的运用,像各种单据.报表.账户等等.在PPT演示文稿中同样不可避免的应用到各种数据表格.对于在PPT中插入表格,我发现了一个新方法,不过我用到了一款免费的.NET ...

  6. GridView中的编辑和删除按钮,执行更新和删除代码之前的更新提示或删除提示

    在GridView中,可以通过设计界面GridViewr任务->编辑列->CommandField,很简单的添加的编辑和删除按钮 在前台源码中,可以看到GridView自动生成了两个列. ...

  7. [转]GridView中直接新增行、编辑和删除

    本文转自:http://www.cnblogs.com/gdjlc/archive/2009/11/10/2086951.html .aspx <div><asp:Button ru ...

  8. AngularJS进阶(十一)AngularJS实现表格数据的编辑,更新和删除

    AngularJS实现表格数据的编辑,更新和删除 效果 实现 首先,我们先建立一些数据,当然你可以从你任何地方读出你的数据 var app = angular.module('plunker', [' ...

  9. GridView编辑删除

    A前台代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.asp ...

  10. gridview的编辑,更新,取消,自动分页等

    gridview编辑列,把左下角的"自动生成字段"的复选框的勾去掉 添加boundfield(绑定列)将其datafield设置为productname,headertext设置为 ...

随机推荐

  1. centos7.2自带的php5.4升级为5.6

    参考:http://jingyan.baidu.com/article/380abd0a1f176c1d91192c4b.html 今天在新购的阿里云上部署个phpmyadmin,结果显示了个如下信息 ...

  2. ldap基本命令

    前端数据如下: ### frontend.ldif ### dn: dc=ldap,dc=example,dc=com objectclass: top objectclass: dcObject o ...

  3. akka 文章 博客

    http://blog.csdn.net/wsscy2004/article/category/2430395 Actor生命周期理解 Actor生命周期理解 镇图:Actor内功心法图 Actor的 ...

  4. iOS 上架提示ipad需要显示四个方位,而我们只能竖屏的时候的解决办法

    勾选requires sull screen

  5. JavaScript跨域总结与解决办法 什么是跨域

    什么是跨域 1.document.domain+iframe的设置 2.动态创建script 3.利用iframe和location.hash 4.window.name实现的跨域数据传输 5.使用H ...

  6. ubuntu 设置vpn

    百度了资料 http://jingyan.baidu.com/article/fa4125aca7f1b628ad709271.html 1. 设置 VPN CONNECTION 2.configur ...

  7. python 多线程 paramiko实现批量命令输入输出

    远程批量执行命令 实现多线程执行 速度快 实现多并发登录 #-*- coding: utf-8 -*- #!/usr/bin/python import paramiko import threadi ...

  8. 安装sysbench遇到找不到库文件的问题

    export LD_LIBRARY_PATH=/usr/mysql/lib./configure --prefix=/usr/local/sysbench --with-mysql-includes= ...

  9. php的错误和异常处理

    php中try catch的例子: <?php try { if (@mysql_connect('localhost','root','123456')){ // echo 'success! ...

  10. 【多重背包模板】poj 1014

    #include <iostream> #include <stdio.h> #include <cstring> #define INF 100000000 us ...