protected void fillDeptGrid() { Dictionary <String, BackEndObjects.DeptDetails> deptDict = BackEndObjects.DeptDetails. getAllDeptDetailsForEntIdDB(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString()); DataTable dt = new DataTable(); dt.Columns.Add("dept_id"); dt.Columns.Add("name"); dt.Columns.Add("desc"); dt.Columns.Add("head"); int count = 0; foreach (KeyValuePair <String, BackEndObjects.DeptDetails> kvp in deptDict) { dt.Rows.Add(); dt.Rows[count]["dept_id"] = kvp.Value.getDeptId(); dt.Rows[count]["name"] = kvp.Value.getDeptName(); dt.Rows[count]["desc"] = kvp.Value.getDeptDescription(); dt.Rows[count]["head"] = kvp.Value.getDeptHeadUsrId(); count++; } if (count > 0) { GridView_Dept.DataSource = dt; GridView_Dept.DataBind(); GridView_Dept.Visible = true; Session[SessionFactory.ADMIN_PREF_DEPT_MGMT_DEPT_GRID] = dt; } }
protected void GridView_Dept_RowUpdating(object sender, GridViewUpdateEventArgs e) { String deptName = ((TextBox)GridView_Dept.Rows[e.RowIndex].Cells[0].FindControl("TextBox_DeptName_Edit")).Text; String descr = ((TextBox)GridView_Dept.Rows[e.RowIndex].Cells[0].FindControl("TextBox_Descr_Edit")).Text; String deptHead = ((DropDownList)GridView_Dept.Rows[e.RowIndex].Cells[0].FindControl("DropDownList_Dept_Head_Edit")).SelectedValue; String deptId = ((Label)GridView_Dept.Rows[e.RowIndex].Cells[0].FindControl("Label_Hidden")).Text; int index = GridView_Dept.Rows[e.RowIndex].DataItemIndex; DataTable dt = (DataTable)Session[SessionFactory.ADMIN_PREF_DEPT_MGMT_DEPT_GRID]; dt.Rows[index]["name"] = deptName; dt.Rows[index]["desc"] = descr; dt.Rows[index]["head"] = deptHead; Session[SessionFactory.ADMIN_PREF_DEPT_MGMT_DEPT_GRID] = dt; try { Dictionary <String, String> whereCls = new Dictionary <string, string>(); Dictionary <String, String> targetVal = new Dictionary <string, string>(); whereCls.Add(BackEndObjects.DeptDetails.DEPT_DETAILS_COL_ENT_ID, Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString()); whereCls.Add(BackEndObjects.DeptDetails.DEPT_DETAILS_COL_DEPT_ID, deptId); targetVal.Add(BackEndObjects.DeptDetails.DEPT_DETAILS_COL_DEPT_DESC, descr); targetVal.Add(BackEndObjects.DeptDetails.DEPT_DETAILS_COL_DEPT_HEAD_USR_ID, deptHead); targetVal.Add(BackEndObjects.DeptDetails.DEPT_DETAILS_COL_DEPT_NAME, deptName); BackEndObjects.DeptDetails.updateDeptDetailsDB(targetVal, whereCls, DBConn.Connections.OPERATION_UPDATE); GridView_Dept.EditIndex = -1; GridView_Dept.DataSource = dt; GridView_Dept.DataBind(); } catch (Exception ex) { } }
protected void Button_Dept_Filter_Click(object sender, EventArgs e) { DataTable dt = (DataTable)Session[SessionFactory.ADMIN_PREF_DEPT_MGMT_DEPT_GRID]; if (!TextBox_DeptName_Search.Text.Trim().Equals("")) { DataTable dtTemp = new DataTable(); dtTemp.Columns.Add("dept_id"); dtTemp.Columns.Add("name"); dtTemp.Columns.Add("desc"); dtTemp.Columns.Add("head"); int count = 0; for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["name"].ToString().IndexOf(TextBox_DeptName_Search.Text.Trim(), StringComparison.InvariantCultureIgnoreCase) >= 0) { dtTemp.Rows.Add(); dtTemp.Rows[count]["dept_id"] = dt.Rows[i]["dept_id"]; dtTemp.Rows[count]["name"] = dt.Rows[i]["name"]; dtTemp.Rows[count]["desc"] = dt.Rows[i]["desc"]; dtTemp.Rows[count]["head"] = dt.Rows[i]["head"]; count++; } } GridView_Dept.DataSource = dtTemp; GridView_Dept.DataBind(); } else { GridView_Dept.DataSource = dt; GridView_Dept.DataBind(); } }
protected void GridView_Dept_RowEditing(object sender, GridViewEditEventArgs e) { GridView_Dept.EditIndex = e.NewEditIndex; GridView_Dept.DataSource = (DataTable)Session[SessionFactory.ADMIN_PREF_DEPT_MGMT_DEPT_GRID]; GridView_Dept.DataBind(); }