gpt4 book ai didi

ASP.NET GridView 默认排序顺序

转载 作者:行者123 更新时间:2023-12-04 13:17:27 25 4
gpt4 key购买 nike

我有一个绑定(bind)到 sql 数据源的简单 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>

最佳答案

public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Set your deault sort expression and direction.
if (String.IsNullOrEmpty(MyGridView.SortExpression)) MyGridView.Sort("SortExpression", SortDirection.Ascending);
}
}

关于ASP.NET GridView 默认排序顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7666230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com