C# – GridView sorting not working with ObjectDataSource

asp.netcgridview

I use a GridView to bind using a ObjectDataSource using the DataSource property. Now, the problem is that I've a integer field which is shown like below:

<asp:GridView ... DataSource="MyObjectDataSource" OnSorting="MyGrdView_Sorting" >
<Columns>
<asp:BoundField DataField="IntegerField" Visible="False" SortExpression="IntegerField" />
</Columns>
</asp:GridView>

I also capture the RowCommand event for my business logic purpose and fire the Sort() method of GridView in there. In case, if I fire the Sort() method from Sorting event handler, I get stack overflow exception which I don't have clue why its happening?

Finally, even after doing the right things which I think are not happening here, sorting is just not working in my GridView with the IntegerField. What I'm doing wrong? 🙁

Best Answer

Firing the Sort() on the Sorting event will fire the Sorting event again thus the stack overflow.

Related Topic