刪除選中項DataGrid中的CheckBox問題

功能: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");//操作刪除語句並且返回傳去的頁面
            }
        }
            }

參考網上源碼!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章