日期:2014-05-17 浏览次数:20545 次
protected void delectAll_Click(object sender, EventArgs e) { delectAll.Attributes.Add("onClick", "javascript:return confirm('确定删除吗?');"); SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["new_conn"].ConnectionString); SqlCommand cmd; for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox cb = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); if (cb.Checked == true) { cmd = new SqlCommand("delete from News where News_id='" + GridView1.DataKeys[i].Value + "'", conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } } Data_Bind(); }