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. 在Activity之间传递数据—传递值对象

    传递有两种方式,一种是类继承自Serializable(Java方式,速度较慢),另一种是类继承自Parcelable(Android方式) 继承自Serializable的时候,实现比较简单,类只需 ...

  2. 《JS权威指南学习总结--4.13运算符》

    一.typeof运算符     typeof是一元运算符,放在其单个操作数的前面,操作数可以是任意类型.返回值为表示操作数类型的一个字符串.     例如:     typeof x          ...

  3. <context:annotation-config/>

    转自:Spring <context:annotation-config/> 解说 在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-c ...

  4. js 放大镜用法bug解决

    <img id="zoom_02" src='img/zhang5.jpg' data-zoom-image="img/zhang5p.jpg" /> ...

  5. C语言隐式强制类型转换

    今天又被精度问题困扰,把最基本的东西忘了. int n = 5; int cnt = 5.5; double sum = (n-cnt);  运算完后sum是 -0.5.不知道什么时候n转换成doub ...

  6. hdu_5792_World is Exploding(树状数组+逆序对)

    题目链接:hdu_5792_World is Exploding 题意: 给你一个数列,让你找有多少个(a,b,c,d)满足a≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab ...

  7. android把图片 视频 保存到相册

    //android把图片文件添加到相册 ContentResolver localContentResolver = getContentResolver(); ContentValues local ...

  8. XTEA加密算法

    XTEA加密算法 #include <stdint.h> /* take 64 bits of data in v[0] and v[1] and 128 bits of key[0] - ...

  9. Java学习笔记之类和对象

    1.类是对象的抽象,对象是类的实例. 2.一个.java 文件,只能有一个公有类. 3.Java的默认访问权限是:default,即不加任何访问修饰符,该权限设置只能在同一包访问.   当前类 同一包 ...

  10. 【jsp exception】如何处理jsp页面的错误

    根据jsp对错误的处理方式不同可以将其分为局部异常处理和全局异常处理.局部异常处理适用于个别jsp页面,当这些页面发生错误后,采取特殊的处理方式:全局异常处理适用于所有jsp页面,当所有页面发生某些指 ...