在GRIDVIEW里做多项选择删除,用CHECKBOX,删除代码如下
protected void Button1_Click(object sender, EventArgs e)
{
int i;
string sql = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString();
SqlConnection strConn = new SqlConnection(sql);
strConn.Open();
DataSet ds = new DataSet();
for (i = 0; i < this.GridView1.Rows.Count; i++)
{
if (((CheckBox)this.GridView1.Rows[i].Cells[3].FindControl("CheckBox1")).Checked == true)
{
string StrCom = "delete from news where biaoti ='" + this.GridView1.Rows[i].Cells[1].Text.ToString() + "'";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(StrCom, strConn);
da.Fill(ds, "news");
}
} GridView1.DataBind();
但是执行时if (((CheckBox)this.GridView1.Rows[i].Cells[3].FindControl("CheckBox1")).Checked == true)
判断错误,执行不下去是什么原因,如果给IF里付具体值可以删除.