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. ContentPlaceHolderID属性

    用来对应包含与当前内容关联的 ContentPlaceHolder 的 ID啊 说白了就是去找母版页相应的ContentPlaceHolder ,然后把内容扔进那里面去 <asp:Content ...

  2. Eclipse配置--智能补全

    定位到:Windows→Preferences→Java→Editor→Content Assist 将Auto Activation triggers for java的默认值“.”修改为" ...

  3. spark java 代码example

    https://github.com/apache/spark/tree/master/examples/src/main/java/org/apache/spark/examples

  4. A框架 第三步 先加载父类,如果加载子类.立马报错.里面继承的父类还没有导入

    先导入  超级父类 如object.php ----controller.php 框架文件中 后导入  当前请求的controller的抽象父类(controller_abstract) 最后  导入 ...

  5. 二分图匹配之KM求二分图最佳匹配算法

    参考网址:http://blog.163.com/suntroop@yeah/blog/static/17012103120115185927194/ 对于具有二部划分( V1, V2 )的加权完全二 ...

  6. NSBundle的用法

    bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 对应bundle,cocoa提供了类NSBu ...

  7. Ubuntu 网管服务器配置

    1.设置Linux内核支持ip数据包的转发 echo "1" > /proc/sys/net/ipv4/ip_forward or vi /etc/sysctl.conf   ...

  8. c++面试题【转】

    语言部分: 虚函数,多态.这个概念几乎是必问. STL的使用和背后数据结构,vector string map set 和hash_map,hash_set 实现一个栈类,类似STL中的栈.这个题目初 ...

  9. DataBinding

    <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http ...

  10. selenium2(WebDriver) API

    selenium2(WebDriver) API 作者:Glen.He出处:http://www.cnblogs.com/puresoul/  1.1  下载selenium2.0的包 官方downl ...