I am working on a ListView , and I feel that I am doing something fundamentally wrong when it comes to implementing sorting. Instead of depending on the values โโof List1.SortExpression and List1.SortDirection , I resort to hidden fields because List1.SortExpression always empty and List1.SortDirection always SortDirection.Ascending .
On my .aspx page: (irrelevant code edited)
<asp:HiddenField runat="server" ID="hdnSortExpression" /> <asp:HiddenField runat="server" ID="hdnSortDirection" /> <asp:ListView runat="server" ID="List1" OnItemCommand="List1_ItemCommand" OnSorting="List1_Sorting"> <LayoutTemplate> <table border="0" cellpadding="1"> <thead> <tr> <th><asp:LinkButton runat="server" ID="BtnCompanyCode" CommandName="Sort" CommandArgument="CompanyCode" Text="Company Code" /></th> ... more columns ... </tr> </thead> <tbody> <tr runat="server" id="itemPlaceholder"></tr> </tbody> </table> </LayoutTemplate>
In my code:
protected void List1_ItemCommand(object sender, ListViewCommandEventArgs e) {
This works - each column is sorted correctly by clicking on the same column, it changes the sort direction, but I must conclude that I connected it incorrectly, because I cannot depend on the SortDirection and SortExpression . What am I doing wrong?
source share