怎么样批量删除gridview被选中的行
展开全部
删除一行和删除多行其实是一样的for (int i = 0; i < this.GridView1.Rows.Count; i++)
你既然循环了GridView1的每一行,也获得的每一行的CheckBoxthis.GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox 那么删除多行也就是调用多次using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["sqlStr"].ConnectionString))
{
conn.Open();
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "delete from users where id=@id";
你既然循环了GridView1的每一行,也获得的每一行的CheckBoxthis.GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox 那么删除多行也就是调用多次using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["sqlStr"].ConnectionString))
{
conn.Open();
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "delete from users where id=@id";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询