我用下面的方法实现了,可是我要计算一共删除了多少条数据,要如何弄呢,也就是说前面选择了几条数据     
 foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox cb = (CheckBox)row.FindControl("CheckBox1");            if (cb.Checked)
            {
                string delnum = GridView1.Rows.Count.ToString();
                int strid = int.Parse(GridView1.DataKeys[row.RowIndex].Value.ToString());
                Label1.Text = strid.ToString();
                SqlConnection con = db.createCon();
                con.Open();
                SqlCommand cmd = new SqlCommand("delete from cwissrec where Recid=" + strid + "", con);
                cmd.ExecuteReader();
                Response.Write("<script>alert('成功删除" + delnum + "条数据,现在将为您转到资源列表');window.document.location.href='admin_RecList.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('您没有选择要删除的项目')</script>");
            }
        }

解决方案 »

  1.   

    int tmp =  cmd.ExecuteNonQuery();
     Response.Write("<script>alert('成功删除" + tmp.ToString() + "条数据,现在将为您转到资源列表');window.document.location.href='admin_RecList.aspx';</script>");
      

  2.   

    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    foreach (GridViewRow row in GridView1.Rows)
                    {
                        CheckBox cb = (CheckBox)row.FindControl("CheckBox1");                    if (cb.Checked)
                        {
                            
                            int strid = int.Parse(GridView1.DataKeys[row.RowIndex].Value.ToString());
                            sb.Append("'"+strid.ToString()+"',");
                        } 
                    }
                    if(sb.Length>0)
                    {
                        SqlConnection con = db.createCon();
                        con.Open();
                        SqlCommand cmd = new SqlCommand("delete from cwissrec where Recid in (" + sb.ToString().TrimEnd(",".ToCharArray()) + ")", con);
                        int delnum = cmd.ExecuteNonQuery();
                        Response.Write("<script>alert('成功删除" + delnum + "条数据,现在将为您转到资源列表');window.document.location.href='admin_RecList.aspx';</script>");                }