I am trying to sort GridView based on click in header, when paging is alowed.
How to retrieve content of the grid?
GridView.Rows only gives me rows on the selected page.
I don't want to do another select from Database and than order it. And also, don't want to save it in SessionState.
I can't figure out what 'default' SortExpression looks like.
And this SortExpression will order DESC or ASC by ID, but how to do some custom sort ? Or to sort by other type?
How to sort by ValueFromIncluded
//example
<asp:GridView runat="server"
ID="GridID"
SelectMethod="GridView_GetData"
ItemType="ItemType"
AllowPaging="true">
<Columns>
<asp:TemplateField HeaderText="Id" SortExpression="Id">
<ItemTemplate>
<asp:Label runat="server" Text='<%# Item?.Id%>'/>
</ItemTemplate>
</asp:TemplateField>
asp:TemplateField HeaderText="ValueFromIncluded" SortExpression="ValueFromIncluded">
<ItemTemplate>
<asp:Label runat="server" Text='<%# Item?.ValueFromIncluded.SomeOtherId%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
// SelectMethod.
public IQueryable<ItemType> GridView_GetData()
{
IQueryable<ItemType> q = dbx.ItemType
.Include(f => f.OtherType);
}
switch caseon theSortExpressionand then call appropriateOrderByon the specific property ofItemType