GridView和checkbox套用 批量删除

Posted on 2010-11-22 14:21  孤∮帆  阅读(323)  评论(0编辑  收藏  举报

  foreach (GridViewRow gvwr in GridView1.Rows)
        {
            if (((CheckBox)gvwr.FindControl("CheckBox1")).Checked == true)
            {
                int ID = Convert.ToInt32(GridView1.DataKeys[gvwr.RowIndex].Value.ToString());             
                OleDbConnection Conn = new OleDbConnection(ConnStr);
                Conn.Open();
                OleDbCommand cmd = new OleDbCommand("delete from liuyan where ID = " + ID + "", Conn);
                cmd.ExecuteNonQuery();          
                Conn.Close();
            }
        }

 

        OleDbConnection conn = new OleDbConnection(ConnStr);
        conn.Open();
        OleDbDataAdapter dr = new OleDbDataAdapter("SELECT * FROM liuyan order by ID desc", conn);
        DataSet ds = new DataSet();
        dr.Fill(ds, "liuyan");
        GridView1.DataSource = ds;
        GridView1.DataBind();
        conn.Close();

Copyright © 2024 孤∮帆
Powered by .NET 9.0 on Kubernetes