protected void Button3_Click(object sender, EventArgs e) { //for (int i = 0; i < GridView1.Rows.Count; i++) //{ // CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[2].FindControl("CheckBox1"); // if (chk != null) // { foreach (GridViewRow row in GridView1.Rows) { if (row.RowType == DataControlRowType.DataRow) { CheckBox chkRow = (row.Cells[2].FindControl("CheckBox1") as CheckBox); if (chkRow.Checked) { // if (!Page.IsPostBack) string strID = row.Cells[0].Text; string Pages = row.Cells[1].Text; string status = "Y"; con.Open(); string query = "Update Role1 set [Add] ='" + status + "' where ID= '" + strID + "' and Pages= '" + Pages + "'"; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); GridView1.DataBind(); con.Close(); } else { string strID = row.Cells[0].Text; string Pages = row.Cells[1].Text; string status = "N"; //cmd = new SqlCommand("insert into Role1(Checkin_Add) values(" + status + " where ID= '" + strID + "' and Role_Name='" + strName + "')", con); string query = "Update Role1 set [Add] ='" + status + "' where ID= '" + strID + "' and Pages= '" + Pages + "'"; SqlCommand cmd = new SqlCommand(query, con); con.Open(); cmd.ExecuteNonQuery(); GridView1.DataBind(); con.Close(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //Your existing code } }
Save
Session
ViewState
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)