我有一個簡單的gridview控件綁定到一個sql數據源。現在我啓用了排序功能,但是當我單擊要排序的列時,它會先按升序排序。當我再次單擊同一列時,它按降序對其進行排序。我想切換。我希望它在第一次點擊時降序排列,然後升序第二次。我怎麼做?ASP.NET GridView默認排序順序
這裏是我的GridView控件代碼:
<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" >
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Team" HeaderText="Team" SortExpression="Team" />
<asp:BoundField DataField="Matches" HeaderText="Matches"
SortExpression="Matches" />
<asp:BoundField DataField="Points" HeaderText="Points"
SortExpression="Points" />
<asp:BoundField DataField="Tries" HeaderText="Tries" SortExpression="Tries" />
<asp:BoundField DataField="Conversions" HeaderText="Conversions"
SortExpression="Conversions" />
<asp:BoundField DataField="Penalties" HeaderText="Penalties"
SortExpression="Penalties" />
<asp:BoundField DataField="Drop Goals" HeaderText="Drop Goals"
SortExpression="Drop Goals" />
<asp:BoundField DataField="Yellow Cards" HeaderText="Yellow Cards"
SortExpression="Yellow Cards" />
<asp:BoundField DataField="Red Cards" HeaderText="Red Cards"
SortExpression="Red Cards" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [statstable]"></asp:SqlDataSource>
看。 http://stackoverflow.com/questions/702600/sorting-and-paging-with-gridview-asp-net, http://msdn.microsoft.com/en-us/library/hwf94875.aspx, http://www.netomatix.com/development/GridViewSorting.aspx – jlg