2
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        AllowPaging="true" AllowSorting="true" PageSize="10" DataKeyNames="CategoryID" 
        onselectedindexchanged="GridView1_SelectedIndexChanged" 
        GridLines="Vertical" onrowediting="GridView1_RowEditing" 
        onrowcancelingedit="GridView1_RowCancelingEdit" 
        onrowupdating="GridView1_RowUpdating" onsorted="GridView1_Sorted" 
        onsorting="GridView1_Sorting">
        <Columns>
        <asp:BoundField DataField="categoryid" HeaderText="ID" SortExpression="CategoryID" />        
        </Columns>        
    </asp:GridView>

排序不起作用。我错过了什么?

4

1 回答 1

1

在您的排序事件处理程序中,您可以更改数据表上的排序属性。

  dt.DefaultView.Sort = e.SortExpression + " ASC";
  gv.DataSource = dt;
  gv.DataBind();

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorting.aspx

于 2012-05-06T18:33:09.977 回答