GridView实现数据编辑和删除
2023-04-11 10:47:04 阅读次数:305
< 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" > |
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 = "联系电话" /> |
15 |
< asp:CommandField ShowEditButton = "True" /> //编辑 |
16 |
< asp:CommandField ShowDeleteButton = "True" /> //删除 |
后台代码:
04 |
public void Emplogin_Bind() |
06 |
this.gv_Emplogin.DataSource = em.EmploginInfo(); |
07 |
this.gv_Emplogin.DataBind(); |
13 |
/// <param name= "sender" ></param> |
14 |
/// <param name= "e" ></param> |
15 |
protected void gv_Emplogin_RowDeleting(object sender, GridViewDeleteEventArgs e) |
17 |
int Emp_id=int.Parse(gv_Emplogin.Rows[e.RowIndex].Cells[0].Text); |
18 |
if (em.Del_EmploginInfo(Emp_id) == 1) |
27 |
/// <param name= "sender" ></param> |
28 |
/// <param name= "e" ></param> |
29 |
protected void gv_Emplogin_RowEditing(object sender, GridViewEditEventArgs e) |
31 |
gv_Emplogin.EditIndex=e.NewEditIndex; |
38 |
/// <param name= "sender" ></param> |
39 |
/// <param name= "e" ></param> |
40 |
protected void gv_Emplogin_RowUpdating(object sender, GridViewUpdateEventArgs e) |
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) |
52 |
gv_Emplogin.EditIndex = -1; |
60 |
/// <param name= "sender" ></param> |
61 |
/// <param name= "e" ></param> |
62 |
protected void gv_Emplogin_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) |
64 |
gv_Emplogin.EditIndex = -1; |
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/rongfengliang/3104507,作者:rongfengliang,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:HorizontalScrollView包裹RecyclerView,使用StaggeredGridLayoutManager均分网格形成表格状列表,不固定列,每次刷新数据列位置异常错乱变动问题
下一篇:把一个数组(列表)中的数据逆向反转,python