Hi, i am trying to implement a simple example of bubbling in Gridview WITH two
checkboxes(headertemplate("chkall")
and
itemtemplate("chksingle"))
in Gridview. I m using c# 4.0 with sql server 2008.
I have two issues in this simple program:
a) whenever i am trying to check/uncheck the chkall(whose autopostback proerty is set to 'true'), it does nt work.
b) WHen i chk on some checkboxes, and click on a 'delete' button somewhere on the web-form, it doesnot work...
please help me rectifying the following code....
protected void chkall_CheckedChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chksingle = (CheckBox)row.Cells[0].FindControl("chksingle");
chksingle.Checked = ((CheckBox)sender).Checked;
}
}
void DBind()
{
con = new SqlConnection("server=.;database=shikhar;integrated security=true");
adap = new SqlDataAdapter("select * from emp", con);
ds = new DataSet();
adap.Fill(ds, "emp");
GridView2.DataSource = ds.Tables[0];
GridView2.DataBind();
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=.;database=shikhar;integrated security=true");
con.Open();
foreach (GridViewRow row in GridView2.Rows)
{
CheckBox chksingle = row.Cells[0].FindControl("chksingle") as CheckBox;
if (chksingle.Checked)
{
SqlCommand cmd = new SqlCommand("delete employee where id='"+row.Cells[1].Text+"'",con);
cmd.ExecuteNonQuery();
}
}
con.Close();
con.Dispose();
DBind();
}
}
[Edited]Code is wrapped in "pre" tags[/Edited]
[edit]Urgency deleted: It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response. - OriginalGriff[/edit]