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配合使用,相匹配绑定数据: 二.样式 ...
随机推荐
- (GoRails) 如何去掉form输入框头尾的空格;何时用callbacks,gem;
视频:https://gorails.com/episodes/when-callbacks-and-adding-dependencies-are-good?autoplay=1 主题:应当在什么时 ...
- Confluence 6 选项 2 – 转移 Crowd/Jira 应用程序中的用户和用户组到 Confluence 数据库
当你打算合并的外部目录服务器(Crowd 或 Jira 应用)有大量的用户到 Confluence 数据库中的时候,请使用这个选项.你需要有基本的 SQL 知识才能完成这个任务. 下面的 SQL 命令 ...
- 『科学计算_理论』SVD奇异值分解
转载请声明出处 SVD奇异值分解概述 SVD不仅是一个数学问题,在工程应用中的很多地方都有它的身影,比如前面讲的PCA,掌握了SVD原理后再去看PCA那是相当简单的,在推荐系统方面,SVD更是名声大噪 ...
- Python面向对象编程、类
一.面向对象编程 面向对象--Object Oriented Programming,简称oop,是一种程序设计思想.在说面向对象之前,先说一下什么是编程范式,编程范式你按照什么方式来去编程,去实现一 ...
- python-day15函数递归
1.递归: 在函数内,调用自己. (技巧: 每次调用时,函数前面需加上return,这样返回值就可以一层一层 的返回去) #def age(n):# if n == 1:# re ...
- ubuntu系统连接windows系统
1,首先我们要在ubuntu系统是输入:sudo apt-get install rdesktop 2, 用法: rdesktop[options] server[:port] .其实我们就可 ...
- Linux 强制安装rpm 包
Linux 强制安装rpm 包 2014年12月12日 10:21 [root@ilearndb1 Server]# rpm -ivh unixODBC-devel-2.* --nodeps -- ...
- @ConditionalOnProperty 详解
@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) @Documented @Con ...
- 深入理解$watch ,$apply 和 $digest --- 理解数据绑定过程——续
Angular什么时候不会自动为我们$apply呢? 这是Angular新手共同的痛处.为什么我的jQuery不会更新我绑定的东西呢?因为jQuery没有调用$apply,事件没有进入angular ...
- spring cloud学习(四) Fegin 的使用
Feign 的使用 什么是Feign? Feign : Declarative REST clients. Feign 是一个声明web服务客户端,这便得编写web服务客户端更容易,使用Feign 创 ...