protected void Grd_Group_RowEditing(object sender, GridViewEditEventArgs e) { Grd_Group.EditIndex = e.NewEditIndex; getcon(); string str = "select group_name,group_description,group_id from tbl_group"; SqlCommand cmd = new SqlCommand(str, con); SqlDataAdapter ad1 = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); ad1.Fill(dt); if (dt.Rows.Count > 0) { Grd_Group.DataSource = dt; Grd_Group.DataBind(); } }
protected void Btn_View_Click(object sender, EventArgs e) { getcon(); string str1 = "select group_name,group_description,group_id from tbl_group"; SqlCommand cmd1 = new SqlCommand(str1, con); SqlDataAdapter ad1 = new SqlDataAdapter(cmd1); DataTable dt1 = new DataTable(); ad1.Fill(dt1); if (dt1.Rows.Count > 0) { Grd_Group.DataSource = dt1; Grd_Group.DataBind(); } con.Close(); }
protected void Grd_Group_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { getcon(); Grd_Group.EditIndex = -1; string str1 = "select group_name,group_description,group_id from tbl_group"; SqlCommand cmd1 = new SqlCommand(str1, con); SqlDataAdapter ad1 = new SqlDataAdapter(cmd1); DataTable dt1 = new DataTable(); ad1.Fill(dt1); if (dt1.Rows.Count > 0) { Grd_Group.DataSource = dt1; Grd_Group.DataBind(); } con.Close(); }
protected void Grd_Group_RowDeleting(object sender, GridViewDeleteEventArgs e) { getcon(); string dk = Grd_Group.DataKeys[e.RowIndex].Values[0].ToString(); string str = "delete from tbl_group where group_id='" + dk + "'"; SqlCommand cmd = new SqlCommand(str, con); cmd.ExecuteNonQuery(); string str1 = "select group_name,group_description,group_id from tbl_group"; SqlCommand cmd1 = new SqlCommand(str1, con); SqlDataAdapter ad = new SqlDataAdapter(cmd1); DataTable dt1 = new DataTable(); ad.Fill(dt1); if (dt1.Rows.Count > 0) { Grd_Group.DataSource = dt1; Grd_Group.DataBind(); } con.Close(); }
protected void Grd_Group_RowUpdating(object sender, GridViewUpdateEventArgs e) { getcon(); string dk = Grd_Group.DataKeys[e.RowIndex].Values[0].ToString(); string gname = ((TextBox)Grd_Group.Rows[e.RowIndex].Cells[0].Controls[0]).Text; string gdescription = ((TextBox)Grd_Group.Rows[e.RowIndex].Cells[1].Controls[0]).Text; string str = "update tbl_group set group_name='" + gname + "',group_description='" + gdescription + "' where group_id='" + dk + "'"; SqlCommand cmd = new SqlCommand(str, con); cmd.ExecuteNonQuery(); Grd_Group.EditIndex = -1; string str3 = "select group_name,group_description,group_id from tbl_group"; SqlCommand cmd1 = new SqlCommand(str3, con); SqlDataAdapter ad1 = new SqlDataAdapter(cmd1); DataTable dt1 = new DataTable(); ad1.Fill(dt1); if (dt1.Rows.Count > 0) { Grd_Group.DataSource = dt1; Grd_Group.DataBind(); } con.Close(); }