2009-09-04 62 views
1
protected void ButtonDelete_Click(object sender, EventArgs e) 
{ 
DataSet ds; 

if (Session["location1"] != null) 
{ 
ds = (DataSet)Session["location1"]; 

//int cnt = ds.Tables[0].Rows.Count; 

//for (int i = 0; i < cnt; i++) 
//{ 
//} 


foreach (DataGridItem item in DataGrid1.Items) 
{ 
HtmlInputCheckBox chk = new HtmlInputCheckBox(); 

chk = (HtmlInputCheckBox)item.Cells[0].FindControl("DeleteThis"); 
if (chk.Checked == true) 
{ 

objaccess.Option = "AA"; 
string Location = item.Cells[0].Text.ToString(); 

//objaccess.Locationcode = item.Cells[0].Text.ToString(); 
// string strop = item.Cells[0].Text.ToString(); 
objaccess.delInvsItem(); 
//this.DeleteGridRow(index); 

} 
} 

這裏我用上面的代碼來刪除datagrid中的記錄,而不是在gridview中使用複選框。在選項「AA」中,我在後端寫入了刪除查詢。一旦我選擇了datagrid中的複選框,然後我按下了delete鍵,上面的函數就被完美地調用了,但執行後記錄沒有被刪除。如何刪除datagrid以及數據庫

回答

1

我不確定您的代碼,但最好從數據庫中刪除記錄,然後重新填充數據集。

相關問題