Error when deleting one last row from GridView in asp.net

kahvedzic
kahvedzic used Ask the Experts™
on
Hi,

in gridview I have only one row when I try to delete it I get message from picture. I have trigger on table from where I delete row, when I disable trigger everything works fine. Also if there is more than one row in gridview no error appears. Is it possible to have trigger for delete on table and not have this error on last row delete from gridview?

Thanks error on delete
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
From the error, it looks like you are assigning an invalid value to the GridView.SelectedIndex.    SelectedIndex is zero-based, meaning the index starts at 0 for the first row.  If there are no rows, the default value is -1.

The ArgumentOutOfException error happens when the SelectedIndex property is set to a value less than -1.  Try assigning a default value of -1 to the selectedindex if there are no more rows in the GridView.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindex%28VS.80%29.aspx

Kaushal AroraTechnical Analyst

Commented:
Can you post your code, so that we can get the information why you get this exception.
SharePoint Architect
Commented:
After Deleting just Bind the Grid Again and try or give me your code i'll fix it...

Regards,
Amit Tripathi

Author

Commented:
I bind the Grid on a RowDeleted event and it works like a charm.

Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial