I have insert gridview datas into database using checkbox checked. My prob is when datas present in database checkbox should be checked.
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("adminname"), new DataColumn("projectname") });
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
GridViewRow row = GridView1.Rows[i];
CheckBox CheckBox1 = (row.Cells[0].FindControl("CheckBox1") as CheckBox);
if (CheckBox1.Checked == true && CheckBox1 != null)
{
string adminname = (row.Cells[1].FindControl("Label1") as Label).Text;
string projectname = Label6.Text;
dt.Rows.Add(adminname, projectname);
SqlConnection conn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SUJAY;Data Source=SUPREME6-PC");
conn.Open();
String s = "Insert into admintab values('" + adminname + "','" + projectname + "')";
SqlCommand cmd = new SqlCommand(s, conn);
cmd.ExecuteNonQuery();
CheckBox1.DataBind();
conn.Close();
}
else
{
SqlConnection conn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SUJAY;Data Source=SUPREME6-PC");
conn.Open();
String s = "Delete *from admintab";
SqlCommand cmd = new SqlCommand(s, conn);
cmd.ExecuteNonQuery();
conn.Close();
}