views:

472

answers:

1

I have an ASP.NET GridView that just won't sort! I'm sure that I am missing something pretty obvious.

Page.aspx

<asp:GridView ID="TimeAwayGridView" runat="server" AutoGenerateSelectButton="False"
    AutoGenerateEditButton="False" AutoGenerateDeleteButton="False" AllowPaging="False"
    AllowSorting="True" CssClass="gridview" OnSorting="TimeAwayGridView_Sorting">
    <Columns>
        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
        <asp:BoundField DataField="Hours" HeaderText="Hours" SortExpression="Hours" />
    </Columns>
    <EmptyDataTemplate>
        There are currently no items in this table.
    </EmptyDataTemplate>
</asp:GridView>

Page.aspx.cs

protected void TimeAwayGridView_Sorting(object sender, GridViewSortEventArgs e)
{

}
+1  A: 

Asp.Net Datagrip provides you with sorting event, and name of the column that was clicked in GridViewSortEventArgs, but you have to provide you own sort implementation in TimeAwayGridView_Sorting function. Meaning you should sort your datasource and rebind the datagrid.

Alex Reitbort