Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET GridView Default Sorting Order
    text
    copied!<p>I have a simple gridview control bound to an sql datasource. Now I enabled sorting, but when I click on a column to be sorted, it sorts it in an Ascending Order first. When I click the same column again, it sorts it in a Descending order. I want to switch that around. I want it to sort Descending on the first click, and Ascending the second. How do I do that?</p> <p>Here is my Gridview Control code:</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical" &gt; &lt;AlternatingRowStyle BackColor="#CCCCCC" /&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="Name" HeaderText="Name" /&gt; &lt;asp:BoundField DataField="Team" HeaderText="Team" SortExpression="Team" /&gt; &lt;asp:BoundField DataField="Matches" HeaderText="Matches" SortExpression="Matches" /&gt; &lt;asp:BoundField DataField="Points" HeaderText="Points" SortExpression="Points" /&gt; &lt;asp:BoundField DataField="Tries" HeaderText="Tries" SortExpression="Tries" /&gt; &lt;asp:BoundField DataField="Conversions" HeaderText="Conversions" SortExpression="Conversions" /&gt; &lt;asp:BoundField DataField="Penalties" HeaderText="Penalties" SortExpression="Penalties" /&gt; &lt;asp:BoundField DataField="Drop Goals" HeaderText="Drop Goals" SortExpression="Drop Goals" /&gt; &lt;asp:BoundField DataField="Yellow Cards" HeaderText="Yellow Cards" SortExpression="Yellow Cards" /&gt; &lt;asp:BoundField DataField="Red Cards" HeaderText="Red Cards" SortExpression="Red Cards" /&gt; &lt;/Columns&gt; &lt;FooterStyle BackColor="#CCCCCC" /&gt; &lt;HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /&gt; &lt;PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /&gt; &lt;SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /&gt; &lt;SortedAscendingCellStyle BackColor="#F1F1F1" /&gt; &lt;SortedAscendingHeaderStyle BackColor="#808080" /&gt; &lt;SortedDescendingCellStyle BackColor="#CAC9C9" /&gt; &lt;SortedDescendingHeaderStyle BackColor="#383838" /&gt; &lt;/asp:GridView&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;" SelectCommand="SELECT * FROM [statstable]"&gt;&lt;/asp:SqlDataSource&gt; </code></pre>
 

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