LewMawaypag
New Member
I'm working on a \[code\]ListView\[/code\] and am getting that feeling that I'm doing something fundamentally wrong when it comes to implementing sorting. Rather than being able to depend on the values of \[code\]List1.SortExpression\[/code\] and \[code\]List1.SortDirection\[/code\], I'm resorting to hidden fields because \[code\]List1.SortExpression\[/code\] is always blank and \[code\]List1.SortDirection\[/code\] is always \[code\]SortDirection.Ascending\[/code\]. On my .aspx page: (edited out irrelevant code)\[code\]<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>\[/code\]In my Code Behind:\[code\]protected void List1_ItemCommand(object sender, ListViewCommandEventArgs e){ // empty for now}protected void List1_Sorting(object sender, ListViewSortEventArgs e){ SortDirection sortDirection; String sortExpression = e.SortExpression; // how we need to do it in Sorting if (hdnSortExpression.Value.ToLower() == sortExpression.ToLower()) sortDirection = hdnSortDirection.Value =http://stackoverflow.com/questions/12712787/= SortDirection.Ascending.ToString() ? SortDirection.Descending : SortDirection.Ascending; else sortDirection = SortDirection.Ascending; DoSortList(sortExpression, sortDirection); // this sets column headings' sort indicator arrows List1_BindData(sortExpression, sortDirection); // sets DataSource and calls DataBind() // the hacky part: setting hidden fields to store sortExpression and sortDirection hdnEligibilitySortExpression.Value = http://stackoverflow.com/questions/12712787/sortExpression; hdnEligibilitySortDirection.Value = sortDirection.ToString();}\[/code\]It works -- each column gets sorted correctly, clicking the same column reverses sort direction, but I have to conclude that I've wired things up incorrectly because I cannot depend on the \[code\]SortDirection\[/code\] and \[code\]SortExpression\[/code\] properties. What am I doing wrong?