using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml; using System.Data.SqlClient; using System.Data.SqlTypes; public partial class Administrator_ChangeStatus : System.Web.UI.Page { SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString); DataSet ds = new DataSet(); SqlCommand cmd; FillDD objFillDD = new FillDD(); Dashboard objDash = new Dashboard(); protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { lblWhr.Text = ""; Fill_GridUser(); } } private void Fill_GridUser() { try { SqlDataAdapter adp = new SqlDataAdapter("select * from tbl_UserAccount a inner join tbl_Department b on a.DeptId = b.DeptId " + lblWhr.Text + " Order By Id Desc", con); adp.Fill(ds, "User1"); adp.Dispose(); GVUser.DataSource = ds.Tables["User1"]; GVUser.DataBind(); if (GVUser.Rows.Count < 1) { lblDgErr.Text = "Alert! : Zero Records in Database"; } else { objDash.Count_Total(ref lblDGCount, "Id", "tbl_UserAccount", lblWhr.Text, ref lblDgErr); } } catch (Exception ex) { lblDgErr.Text = ("GV Alert! : " + ex.Message); } } protected void RBtnStatus_SelectedIndexChanged(object sender, EventArgs e) { if (RBtnStatus.SelectedItem.Text.Trim() == "Active") { lblWhr.Text = "where status='Active'"; } else { lblWhr.Text = "where status='InActive'"; } Fill_GridUser(); } protected void GVUser_PageIndexChanging(object sender, GridViewPageEventArgs e) { lblDgErr.Text = ""; try { GVUser.PageIndex = e.NewPageIndex; Fill_GridUser(); } catch (Exception exp) { lblDgErr.Text = ("GV Paging Alert! : " + exp.Message); } } protected void GVUser_RowUpdating(object sender, GridViewUpdateEventArgs e) { lblDgErr.Text = ""; String Dgid; String Stat = ""; int row = e.RowIndex; try { Dgid = ((Label)(GVUser.Rows[row].FindControl("lblDgId"))).Text; Label lblStat = ((Label)(GVUser.Rows[row].FindControl("lblDgStatus"))); if (lblStat.Text.Trim() == "Active") { Stat = "InActive"; } else if (lblStat.Text.Trim() == "InActive") { Stat = "Active"; } string strActive = "Update tbl_UserAccount set Status='" + Stat + "' where Id='" + Dgid + "'"; cmd = new SqlCommand(strActive, con); con.Open(); cmd.ExecuteNonQuery(); lblDgErr.Text = "Data Updated Successfully"; } catch (Exception exp) { lblDgErr.Text = "GV Update Alert : " + exp.Message; } finally { if (con.State != ConnectionState.Open) { con.Open(); } Fill_GridUser(); } } protected void GVUser_RowDataBound(object sender, GridViewRowEventArgs e) { try { if (e.Row.RowType == DataControlRowType.DataRow) { Label lblStatId = (Label)e.Row.FindControl("lblDgStatus"); if (lblStatId.Text.Trim() == "InActive") { lblStatId.CssClass = "redtext1"; } } } catch (Exception exp) { lblDgErr.Text = ("GV DataBound Alert! : " + exp.Message); } } }