protected void ckCheckAll_CheckedChanged(object sender, EventArgs e)
{ for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("ckbSelect");
if (ckCheckAll.Checked == true)
{
cbox.Checked = true; }
else
{
cbox.Checked = false;
}
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cboAll = (CheckBox)GridView1.Rows[i].FindControl("ckCheckAll");
if (cboAll != null)
{
if (cboAll.Checked == true)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["XKPath"]);
con.Open();
string str = "delete from review where id=" +Convert.ToInt32( GridView1.DataKeys[i].Value);
Response.Write(Convert.ToInt32(GridView1.DataKeys[i].Value));
SqlCommand com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
}
}
}
DataBinder();
}
我要获取所有checkbox所选中的值看是否选中然后把所有选中的每条记录删掉这样哪里错吗 哪位大哥帮我看看
{ for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("ckbSelect");
if (ckCheckAll.Checked == true)
{
cbox.Checked = true; }
else
{
cbox.Checked = false;
}
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cboAll = (CheckBox)GridView1.Rows[i].FindControl("ckCheckAll");
if (cboAll != null)
{
if (cboAll.Checked == true)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["XKPath"]);
con.Open();
string str = "delete from review where id=" +Convert.ToInt32( GridView1.DataKeys[i].Value);
Response.Write(Convert.ToInt32(GridView1.DataKeys[i].Value));
SqlCommand com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
}
}
}
DataBinder();
}
我要获取所有checkbox所选中的值看是否选中然后把所有选中的每条记录删掉这样哪里错吗 哪位大哥帮我看看
ckbSelect和ckCheckAll调换