I've searched for this without finding anything useful for my case. Closest was this.
I've set AllowSorting="true"
and tried to handle the event fired but I can't get a grasp on how to use it. My SELECT
is done through a controller's method that returns an IEnumerable
filled with objects returned by the query. This method accepts, as one of its parameter, the ORDER BY
clause and construct the SQL query from it and other parameters.
The ORDER BY
parameter comes at the moment from a dropdownlist's value selected by the user. I'm aiming at setting the sorting through clicking the GridView's header. I'd like to be able to catch which column of the header the user clicked so I can pass it in my controller's method and then programmatically rebind my GridView to the results of the query. Also having a way to know if the query should go ASC or DESC depending on the last use.
Here is my GridView :
<asp:GridView ID="GridView1" HorizontalAlign="Center" runat="server"
AllowPaging="True" AutoGenerateColumns="False" AllowSorting="true">
Here is my ObjectDataSource :
<asp:ObjectDataSource ID="objDataSource" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="Get"
TypeName="Type.Name.Here">
<SelectParameters>
//Parameters and their respective controls...
//Order by's control bind to a dropdownlist...
</SelectParameters>
</asp:ObjectDataSource>
I am expecting there is a way to know which column is clicked as well as if it is for an ASC
or DESC
selection. I'd like to be able to use that information the event fired by the user when he clicks the GridView's header so I can pass them in my custom Get(where, params, orderby, top)
method. Which's result can be bind with my GridView.
I think I may be missing some comprehension regarding the interaction of the GridView and its ObjectDataSource. Any help regarding this is also welcome.