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