I have a gridview that I would like to have sortable. When I define it like this:
<asp:GridView ID="GridView1" runat="server" CssClass="gridview" DataSourceID="GridDataSource" AutoGenerateColumns="False" AllowSorting="True" >
The sorting works just fine. ie. when I click the column header the grid sorts by that column.
But when I define it like this:
<asp:GridView ID="GridView1" runat="server" CssClass="gridview" AutoGenerateColumns="False" AllowSorting="True" >
and in codebehind:
GridView1.DataSource = GridDataSource;
GridView1.DataBind();
Using the latter method the sorting does not work. The column headers are links but the grid does not order itself.
I'm setting the DataSource after the page load so the user can chose from some filters (dropdown lists) to restrict the records returned.
Can someone tell me how to set the datasource in codebehind and get sorting functioning? Alternatively a good way to stop the grid from databinding on initial page load.