How to delete a row in a ASP.NET dataGrid
-
Hello experts i would like to know how to delete a row from a dataGrid (which is in edit mode), i am using paging and the built in edit, update, cancel methods. I have been looking all over the posts most seem to be using databases and since i am using a XML file as my surce of data i am abit lost. heres what i have in my delete event Handler.. private void dgStudents_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int rowToDelete = e.Item.ItemIndex; dsStudents.student.Rows[rowToDelete].Delete(); //refresh datagrid control to show changes BindData(); } the rowToDelete int will get the row to delete, but when i run this and click on delete, i get a runtime error of "There is no Row at position 0" Help please?? Cheers
Cheers :)
-
Hello experts i would like to know how to delete a row from a dataGrid (which is in edit mode), i am using paging and the built in edit, update, cancel methods. I have been looking all over the posts most seem to be using databases and since i am using a XML file as my surce of data i am abit lost. heres what i have in my delete event Handler.. private void dgStudents_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int rowToDelete = e.Item.ItemIndex; dsStudents.student.Rows[rowToDelete].Delete(); //refresh datagrid control to show changes BindData(); } the rowToDelete int will get the row to delete, but when i run this and click on delete, i get a runtime error of "There is no Row at position 0" Help please?? Cheers
Cheers :)
hustler2005 wrote:
dsStudents.student.Rows[rowToDelete].Delete();
I guess when page is posted back, you will loose this value. Have you checked the count of rows before issuing delete ?
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions