0

我试过这个

<asp:GridView ID="GvDetails" **runat="server" Width="100%" AutoGenerateColumns="False"
    AllowPaging="True" CssClass="clGrid" PageSize="25" OnRowEditing="GvDetails_RowEditing"
     OnRowCommand="GvDetails_RowCommand"  OnPageIndexChanging="GvDetails_PageIndexChanging"
     EnableModelValidation="True"  AllowSorting="true" EnableSortingAndPagingCallbacks="true"
    onselectedindexchanged="GvDetails_SelectedIndexChanged">
    <Columns>

     <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" >
        <HeaderStyle Width="35%" CssClass="gridHeader"></HeaderStyle>
                                <ItemStyle CssClass="gridItem" HorizontalAlign="Left"></ItemStyle>
      </asp:BoundField>
     </Columns>
</asp:GridView>

但不工作:(

4

1 回答 1

0

DataSource如果要在GridView.

Telerik 和 DevExpress 的控件可以为您执行此操作,但您必须为此付费。

幸运的是,排序DataSource非常容易。

<asp:Button ID="btSort" runat="server">Sort Alphabetically</asp:Button>

然后点击甚至调用这个排序函数

    public void SortAlphabetically()
    {
        List<string> names = // However you get your names

        // Sort from A-Z using Linq
        var sort = from s in names
                   orderby s
                   select s;

        // Set the DataSource and Bind the data
        GvDetails.DataSource = sort;
        GvDetails.DataBind();
    }
于 2012-06-22T13:55:23.033 回答