protected void grdMain_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "cmdEdit") { Response.Redirect("EmployeeMaster.aspx?Emp_Idno=" + e.CommandArgument, true); } //if (e.CommandName == "cmddelete") //{ // Int32 intCompIdno = 1; // AutomobileOnline.DAL.clsEmployeeMaster objEmployeeMaster = new AutomobileOnline.DAL.clsEmployeeMaster(); // int value = objEmployeeMaster.Delete(Convert.ToInt32(e.CommandArgument), intCompIdno); // objEmployeeMaster = null; // if (value > 0) // { // this.BindGrid(); // } //} else if (e.CommandName == "cmdstatus") { Int32 empIdno = Convert.ToInt32((Session["UserIdno"] == null) ? "0" : Session["UserIdno"].ToString()); int intDesgID = 0; bool bStatus = false; string strMsg = string.Empty; string[] strStatus = Convert.ToString(e.CommandArgument).Split(new char[] { '_' }); if (strStatus.Length > 1) { intDesgID = Convert.ToInt32(strStatus[0]); if (Convert.ToBoolean(strStatus[1]) == true) { bStatus = false; } else { bStatus = true; } WebTransport.DAL.EmployeeMasterDAL objEmployeeMaster = new WebTransport.DAL.EmployeeMasterDAL(); int value = objEmployeeMaster.UpdateStatus(intDesgID, bStatus, empIdno); objEmployeeMaster = null; if (value > 0) { this.BindGrid(); strMsg = "Employee Status updated successfully."; txtEmpName.Focus(); } else { strMsg = "Employee Status not updated."; } ScriptManager.RegisterStartupScript(this, this.GetType(), "alertstrMsg", "PassMessage('" + strMsg + "')", true); } } }
private void BindGrid() { WebTransport.DAL.EmployeeMasterDAL objEmployeeMaster = new WebTransport.DAL.EmployeeMasterDAL(); string strEmpName = string.IsNullOrEmpty(txtEmpName.Text.Trim()) ? "" : (txtEmpName.Text.Trim()); Int32 DesigId = Convert.ToInt32(ddlDesignation.SelectedValue) > 0 ? Convert.ToInt32(ddlDesignation.SelectedValue) : 0; var lstGridData = objEmployeeMaster.Select(strEmpName, DesigId); objEmployeeMaster = null; if (lstGridData != null && lstGridData.Count > 0) { DataTable dt = new DataTable(); dt.Columns.Add("S.No", typeof(string)); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Email", typeof(string)); dt.Columns.Add("Date Of Join", typeof(string)); dt.Columns.Add("User Name", typeof(string)); dt.Columns.Add("Designation", typeof(string)); dt.Columns.Add("Status", typeof(string)); int c = 0; for (int i = 0; i < lstGridData.Count; i++) { DataRow dr = dt.NewRow(); dr["S.No"] = ++c; dr["Name"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "Name")); dr["Email"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "Email")); dr["Date Of Join"] = Convert.ToDateTime(DataBinder.Eval(lstGridData[i], "DOJ")).ToString("dd-MM-yyyy"); dr["User Name"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "Username")); dr["Designation"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "Desig_Name")); if (Convert.ToBoolean(DataBinder.Eval(lstGridData[i], "IsActive")) == true) { dr["Status"] = "Active"; } else { dr["Status"] = "Inactive"; } dt.Rows.Add(dr); } if (dt != null && dt.Rows.Count > 0) { ViewState["Dt"] = dt; } grdMain.DataSource = lstGridData; grdMain.DataBind(); lblTotalRecord.Text = "T. Record (s): " + lstGridData.Count; imgBtnExcel.Visible = true; int startRowOnPage = (grdMain.PageIndex * grdMain.PageSize) + 1; int lastRowOnPage = startRowOnPage + grdMain.Rows.Count - 1; lblcontant.Text = "Showing " + startRowOnPage.ToString() + " - " + lastRowOnPage.ToString() + " of " + lstGridData.Count.ToString(); lblcontant.Visible = true; divpaging.Visible = true; } else { grdMain.DataSource = null; grdMain.DataBind(); lblTotalRecord.Text = "T. Record (s): 0 "; imgBtnExcel.Visible = false; divpaging.Visible = false; lblcontant.Visible = false; } foreach (GridViewRow row in grdMain.Rows) { Literal ltrlHide = (Literal)row.FindControl("ltrlHide"); Literal ltrlIsActive = (Literal)row.FindControl("ltrlIsActive"); if (ltrlHide.Text == "False") { ltrlIsActive.Text = "Inactive"; } else { ltrlIsActive.Text = "Active"; } } }