Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void Button7_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                if (Session["Role_Name"] != null && !string.IsNullOrEmpty(Session["Role_Name"].ToString()))
                {
                    CheckBox chkAdd = (row.Cells[1].FindControl("CheckBox1") as CheckBox);
                    CheckBox chkEdit = (row.Cells[2].FindControl("CheckBox2") as CheckBox);
                    CheckBox chkView = (row.Cells[3].FindControl("CheckBox3") as CheckBox);
                    CheckBox chkDelete = (row.Cells[4].FindControl("CheckBox4") as CheckBox);
                    // string strID = row.Cells[0].Text;
                    string Pages = row.Cells[0].Text;
                    con.Open();
                    string query = "Update Role1 set [Add]='" + (chkAdd.Checked == true ? 'Y' : 'N') + "', [View]='" + (chkView.Checked == true ? 'y' : 'N') + "' ,[Edit]='" + (chkEdit.Checked == true ? 'y' : 'N') + "' ,[Delete]='" + (chkDelete.Checked == true ? 'y' : 'N') + "' where Pages ='" + Pages + "' and Role_Name='" + Session["Role_Name"].ToString() + "'";
                    SqlCommand cmd = new SqlCommand(query, con);
                    cmd.ExecuteNonQuery();
                    populateGridview();

                    con.Close();
                }
            }
        } 
    }

Hi, This is my code. In this case checkbox value N is storing in database when i checked the checkbox
Posted
Updated 14-Apr-14 23:29pm
v2
Comments
syed shanu 14-Apr-14 2:16am    
Did you check woth break point chkAdd.Checked == true ? 'Y' .using break point check the chkAdd.Checked Its better to use some string variable for example
String chkAdds="y";
if(chkAdd.Checked )
{
chkAdds="Y";
}
else
{
chkAdds="N";
}
Member 10578683 14-Apr-14 2:46am    
It is coming now .Thanks. But how my checkboxes remain checked when i close the page and again open

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900