删除选中项DataGrid中的CheckBox问题

来源:互联网 发布:周末做什么 知乎 编辑:程序博客网 时间:2024/04/30 01:37

功能:CheckBox选中所选择项,点击 删除所选 Button删除所选项

实现代码: 

   protected void BT_del_Click(object sender, EventArgs e)
    {
        CheckBox cb = new CheckBox();
        for (int i = 0; i < DataGrid1.Items.Count; i++)
        {
            cb = (CheckBox)DataGrid1.Items[i].Cells[0].FindControl("CheckItem");
            if (cb.Checked)
            {
                string sql = "Delete from DB_qiye_news where id=" + DataGrid1.Items[i].Cells[7].Text + "";//获取再DataGrid中的ID值
                 SqlHelper.DelAllSQL(sql,"main.aspx");//操作删除语句并且返回传去的页面
            }
        }
            }

参考网上源码!

原创粉丝点击