2009-09-04 84 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

我不确定您的代码,但最好从数据库中删除记录,然后重新填充数据集。