GridView实现数据编辑和删除
< asp:GridView ID = "gv_Emplogin" runat = "server" AutoGenerateColumns = "False" |
02 |
onrowdeleting = "gv_Emplogin_RowDeleting" |
03 |
onrowupdating = "gv_Emplogin_RowUpdating" |
04 |
onrowediting = "gv_Emplogin_RowEditing" |
05 |
onrowcancelingedit = "gv_Emplogin_RowCancelingEdit" > |
06 |
< Columns > |
07 |
< asp:BoundField DataField = "Emp_id" HeaderText = "用户号" ReadOnly = "True" /> |
08 |
< asp:BoundField DataField = "Emp_name" HeaderText = "登录名" /> |
09 |
< asp:BoundField DataField = "Password" HeaderText = "密码" /> |
10 |
< asp:BoundField DataField = "name" HeaderText = "姓名" /> |
11 |
< asp:BoundField DataField = "Email" HeaderText = "Email" /> |
12 |
< asp:BoundField DataField = "Jb" HeaderText = "用户类型" /> |
13 |
< asp:BoundField DataField = "Tell" HeaderText = "联系电话" /> |
14 |
|
15 |
< asp:CommandField ShowEditButton = "True" /> //编辑 |
16 |
< asp:CommandField ShowDeleteButton = "True" /> //删除 |
17 |
</ Columns > |
18 |
|
19 |
</ asp:GridView > |
后台代码:
01 |
/// <summary> |
02 |
/// GridView的绑定 |
03 |
/// </summary> |
04 |
public void Emplogin_Bind() |
05 |
{ |
06 |
this.gv_Emplogin.DataSource = em.EmploginInfo(); |
07 |
this.gv_Emplogin.DataBind(); |
08 |
} |
09 |
10 |
/// <summary> |
11 |
/// GridView的删除事件 |
12 |
/// </summary> |
13 |
/// <param name= "sender" ></param> |
14 |
/// <param name= "e" ></param> |
15 |
protected void gv_Emplogin_RowDeleting(object sender, GridViewDeleteEventArgs e) |
16 |
{ |
17 |
int Emp_id=int.Parse(gv_Emplogin.Rows[e.RowIndex].Cells[0].Text); |
18 |
if (em.Del_EmploginInfo(Emp_id) == 1) |
19 |
{ |
20 |
Emplogin_Bind(); |
21 |
} |
22 |
} |
23 |
24 |
/// <summary> |
25 |
/// GridView的编辑事件 |
26 |
/// </summary> |
27 |
/// <param name= "sender" ></param> |
28 |
/// <param name= "e" ></param> |
29 |
protected void gv_Emplogin_RowEditing(object sender, GridViewEditEventArgs e) |
30 |
{ |
31 |
gv_Emplogin.EditIndex=e.NewEditIndex; |
32 |
|
33 |
} |
34 |
35 |
/// <summary> |
36 |
/// GridView的更新事件 |
37 |
/// </summary> |
38 |
/// <param name= "sender" ></param> |
39 |
/// <param name= "e" ></param> |
40 |
protected void gv_Emplogin_RowUpdating(object sender, GridViewUpdateEventArgs e) |
41 |
{ |
42 |
int Emp_id=int.Parse(gv_Emplogin.Rows[e.RowIndex].Cells[0].Text); |
43 |
EmployeeInfo ei = new EmployeeInfo(); |
44 |
ei.Emp_name = ((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim(); |
45 |
ei.Pwd = ((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim(); |
46 |
ei.Name = ((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim(); |
47 |
ei.Email = ((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim(); |
48 |
ei.Jb = int.Parse(((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim()); |
49 |
ei.Tell = ((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim(); |
50 |
if (em.Update_EmploginInfo(ei,Emp_id) == 1) |
51 |
{ |
52 |
gv_Emplogin.EditIndex = -1; |
53 |
Emplogin_Bind(); |
54 |
} |
55 |
} |
56 |
57 |
/// <summary> |
58 |
/// GridView取消编辑事件 |
59 |
/// </summary> |
60 |
/// <param name= "sender" ></param> |
61 |
/// <param name= "e" ></param> |
62 |
protected void gv_Emplogin_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) |
63 |
{ |
64 |
gv_Emplogin.EditIndex = -1; |
65 |
Emplogin_Bind(); |
66 |
}
|
GridView实现数据编辑和删除的更多相关文章
- GridView总结二:GridView自带编辑删除更新
GridView自带编辑删除更新逻辑很简单:操作完,重新绑定.总结总结,防止忘记... 效果图: 前台代码: <%@ Page Language="C#" AutoEvent ...
- 自编辑列的gridview,分页,删除,点击删除提示“确认”
分页: gridview的属性中:AllowPaging="True" PageSize="2" 找到gridview的PageIndexChan ...
- Gridview中运用CommandField 删除控件时注意点
我在gridview1 <编辑列>里面添加了一个<CommandField 删除>的控件,之后在gridview1的事件<RowDeleting>事件下 写了一段删 ...
- ASP.NET(C#) GridView (编辑、删除、更新、取消)
转自:http://my.oschina.net/dldlhrmc/blog/93458 前台代码 view source print? 01 <%@ Page Language=" ...
- 20160622001 GridView 删除列 用模板实现删除时提示确认框
GridView在使用CommandField删除时弹出提示框,在.net2005提供的GridView中我们可以直接添加一个 CommandField删除列:<asp:CommandField ...
- ASP.NET中GridView控件删除数据的两种方法
今天在用GridView控件时,发现了一个问题,就是使用GridView控件在删除数据时的问题.接下来我们通过模板列方式和CommandField方式删除某条数据讲解下两者之间的区别. 方式一:通 ...
- GridView使用CommandField删除列实现删除时提示确认框
在.net2005提供的GridView中我们可以直接添加一个CommandField删除列完后在它的RowDeleting事件中完成删除 GridView在使用CommandField删除时弹出提示 ...
- Gridview中 LinkButton删除以及自带删除
<asp:LinkButton ID="lbtnDel" OnClientClick="return confirm('删除新闻会连同其下评论一起删除,是否删除?' ...
- GridView的使用(高度封装,不怎么灵活,repeat可替代)
GridView的使用 首先,gridview是封装好的,直接在设计界面使用,基本不需要写代码: 一.绑定数据源 GridView最好与LinQDatasourse配合使用,相匹配绑定数据: 二.样式 ...
随机推荐
- nyoj737石子合并(一)
先得出区间为1和2时的结果.用arr[i][j]记录i,j内的和.dp[i][j]记录i,j区间全加起来的最小花费.那么区间大小为1和2时都是明显的.为3时枚举断点.其中一个区间大小为1也是可行的. ...
- Import Data from *.xlsx file to DB Table through OAF page(转)
Use Poi.jar Import Data from *.xlsx file to DB Table through OAF page Use Jxl.jar Import Data from ...
- axis2的WebService无法注入Service层类
package com.vrv.paw.axiswebservices; import org.springframework.web.context.ContextLoader; import or ...
- vim 缩进设置
1.在自己的家目录(/home)下建立.vimrc文件.控制台输入vi ~/.vimrc 回车. 2.在.vimrc文件中输入如下文本: set tabstop=4 set softtabstop= ...
- sql存储过程中,如何根据指定日期、月数、天数推算预产日期
我这边有一个业务,根据某个指定日期,推算某个患者的预产日期 原理:比如孕产的预产日期的算法(预产日期 = 末次月经日期+ 10月+8天) 那么我们怎么通过存储过程来实现呢? 首先分析条件 需要一个指定 ...
- 8 标准库C文件
使用标准C库时,下面哪个选项使用只读模式打开文件. A fopen("foo.txt","r");//r 打开只读文件 B fopen("foo.tx ...
- 【译】MVC3 20个秘方-(15)使用CAPTCHA去防止恶意软件自动提交评论(防灌水)
[译]MVC3 20个秘方-(15)使用CAPTCHA去防止恶意软件自动提交评论(防灌水) 问题 有种不太幸运的情况,有人用自动程序去提交表单,在整个互联网中造成大量的垃圾.为了防止这种情况的方法 ...
- Flask初级(五)flash在模板中使用继承,模板的模板
Project name :Flask_Plan templates:templates static:static 继续上一篇文章. 我们不希望每个页面都写一遍引入js,css,导航条……………… ...
- DevExpress v18.1新版亮点——Windows 10 UWP篇
用户界面套包DevExpress v18.1日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress Windows 10 UWP v18.1 的新功能,快来下载 ...
- 《JAVA----day01和day02》
1,(在有符号的情况下)若一个二进制数都是1,则对应的十进制数是-1 2,在定义数值类型时,若无特别说明,整数默认:int 小数默认:double 在内存中 占字节数 取值范围 (1)byte:1个 ...