//protected void DepDisplayGrid_RowUpdating(object sender, GridViewUpdateEventArgs e) //{ //} protected void DepDisplayGrid_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName.Equals("Add")) { DepartmentBLL depManager = new DepartmentBLL(); TextBox txtname = (TextBox)DepDisplayGrid.FooterRow.FindControl("txtAddname"); TextBox txtCode = (TextBox)DepDisplayGrid.FooterRow.FindControl("txtAddCode"); Department depToAdd = new Department(); depToAdd.Name = txtname.Text; depToAdd.Code = txtCode.Text; depManager.Add(depToAdd, connection); } else if (e.CommandName.Equals("UpdateDep")) { DepartmentBLL depManager = new DepartmentBLL(); GridViewRow row = DepDisplayGrid.Rows[DepDisplayGrid.EditIndex]; Label id = (Label)row.FindControl("lblDep_Id"); TextBox name = (TextBox)DepDisplayGrid.Rows[DepDisplayGrid.EditIndex].Cells[0].FindControl("txtname"); TextBox code = (TextBox)DepDisplayGrid.Rows[DepDisplayGrid.EditIndex].FindControl("txtCode"); int selectedId = int.Parse(id.Text); Department depToUpdate = new Department();//= empid.Text; depToUpdate.DepartmentID = selectedId; depToUpdate.Name = name.Text; depToUpdate.Code = code.Text; depManager.Update(depToUpdate, connection); } } catch (Exception exp) { } finally { DepDisplayGrid.EditIndex = -1; BindGrid(false); } }