Im looking to programmatically delete from a GridView.
I have implemented the gridview’s OnRowDeleting="Delete_Record" event handler, and this is called when the user clicks the delete link on the GridView, but as the row doesn’t seem to be selected the code which does the delete does not work.
To test further I can click select, to select the row (commenting out the code behind the select) then if I click delete the code runs fine.
Is there a way to have the row selected as the first step in the Delete_Record?
GridViewRow row = gvResults.SelectedRow;
string id = row.Cells[1].Text;
ASB_DataDataContext db = new ASB_DataDataContext();
var delCase = from dc in db.Inputts
where dc.counter == Convert.ToInt32(id)
select dc;
foreach (var nCase in delCase)
{
db.Inputts.DeleteOnSubmit(nCase);
db.SubmitChanges();
}
Since you are using the event you should be having the required index as part of the
GridViewDeleteEventArgs ewhich should be like saye.RowIndexyou can then access your needed parameter as
grid.Rows[e.RowIndex].Cells[1].Text