2019独角兽企业重金招聘Python工程师标准>>>
前台的html代码:
<asp:GridView ID="gv_Emplogin" runat="server" AutoGenerateColumns="False" onrowdeleting="gv_Emplogin_RowDeleting" onrowupdating="gv_Emplogin_RowUpdating" onrowediting="gv_Emplogin_RowEditing" onrowcancelingedit="gv_Emplogin_RowCancelingEdit"><Columns><asp:BoundField DataField="Emp_id" HeaderText="用户号" ReadOnly="True" /><asp:BoundField DataField="Emp_name" HeaderText="登录名" /><asp:BoundField DataField="Password" HeaderText="密码" /><asp:BoundField DataField="name" HeaderText="姓名" /><asp:BoundField DataField="Email" HeaderText="Email" /><asp:BoundField DataField="Jb" HeaderText="用户类型" /><asp:BoundField DataField="Tell" HeaderText="联系电话" /><asp:CommandField ShowEditButton="True" /> //编辑<asp:CommandField ShowDeleteButton="True" /> //删除</Columns></asp:GridView>
后台代码:
/// <summary>/// GridView的绑定/// </summary>public void Emplogin_Bind(){this.gv_Emplogin.DataSource = em.EmploginInfo();this.gv_Emplogin.DataBind();}/// <summary>/// GridView的删除事件/// </summary>/// <param name="sender"></param>/// <param name="e"></param>protected void gv_Emplogin_RowDeleting(object sender, GridViewDeleteEventArgs e){int Emp_id=int.Parse(gv_Emplogin.Rows[e.RowIndex].Cells[0].Text);if (em.Del_EmploginInfo(Emp_id) == 1){Emplogin_Bind();}}/// <summary>/// GridView的编辑事件/// </summary>/// <param name="sender"></param>/// <param name="e"></param>protected void gv_Emplogin_RowEditing(object sender, GridViewEditEventArgs e){gv_Emplogin.EditIndex=e.NewEditIndex;}/// <summary>/// GridView的更新事件/// </summary>/// <param name="sender"></param>/// <param name="e"></param>protected void gv_Emplogin_RowUpdating(object sender, GridViewUpdateEventArgs e){int Emp_id=int.Parse(gv_Emplogin.Rows[e.RowIndex].Cells[0].Text);EmployeeInfo ei = new EmployeeInfo();ei.Emp_name = ((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();ei.Pwd = ((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();ei.Name = ((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();ei.Email = ((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();ei.Jb = int.Parse(((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim());ei.Tell = ((TextBox)(gv_Emplogin.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim();if (em.Update_EmploginInfo(ei,Emp_id) == 1){gv_Emplogin.EditIndex = -1;Emplogin_Bind();}}/// <summary>/// GridView取消编辑事件/// </summary>/// <param name="sender"></param>/// <param name="e"></param>protected void gv_Emplogin_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e){gv_Emplogin.EditIndex = -1;Emplogin_Bind();}