Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would recommend that you look at this post and reverse the ascending / descending flag logic.</p> <p><a href="https://stackoverflow.com/questions/250037/gridview-sorting-sortdirection-always-ascending">GridView sorting: SortDirection always Ascending</a></p> <p>Your ASPX page will have a gridview like this (pay specific attention to the OnSorting part):</p> <pre><code>&lt;asp:GridView ID="grdHeader" AllowSorting="true" AllowPaging="false" AutoGenerateColumns="false" Width="780" runat="server" OnSorting="grdHeader_OnSorting" EnableViewState="true"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="Entitycode" HeaderText="Entity" SortExpression="Entitycode" /&gt; &lt;asp:BoundField DataField="Statusname" HeaderText="Status" SortExpression="Statusname" /&gt; &lt;asp:BoundField DataField="Username" HeaderText="User" SortExpression="Username" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>Your CodeBehind (aspx.cs) will then need to implement the method grdHeader_OnSorting. The variables in GridViewSortEventArgs will tell you which direction the user asked to sort. In your case you would then do the opposite...such as:</p> <pre><code>protected void grdHeader_OnSorting(object sender, GridViewSortEventArgs e) { List&lt;V_ReportPeriodStatusEntity&gt; items = GetPeriodStatusesForScreenSelection(); SortDirection dir = e.SortDirection == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending; items.Sort(new Helpers.GenericComparer&lt;V_ReportPeriodStatusEntity&gt;(e.SortExpression, dir)); grdHeader.DataSource = items; grdHeader.DataBind(); } </code></pre> <p>Here the items.Sort method is doing all the sorting...all you are doing is taking that sorted result and assigning it back to your datasource.</p> <p>If you want more information on the concept of how to sort a GridView, I'd recommend looking at this example on MSDN: <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sort.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sort.aspx</a></p> <p>Let me know if there is anything else I can do to clarify.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload