tags:

views:

44

answers:

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);

}
}

Here i used the above code to delete records in datagrid not in gridview using checkbox..........in option"AA" i wrote delete query in backend ........once i selected the checkbox in datagrid then pressed the delete key .....above function is called perfectly but after execution records didint deleted...pls help

A: 

I am not sure about your code but it is better to delete a record from the database and then re-populate dataset.

adatapost