views:

114

answers:

2

Hi, I have given an access to stored procedure, which i'm not able to edit. This Stored Procedure returns a Table with 2 Column, what I did is set a GridView's DataSource using SQLDataSource in this stored procedure. but I want this GridView to Sort an specific column to descending whenever this GridView Loads.

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                        DataSourceID="SqlDataSource2" ForeColor="Black" 
                        Width="58%" Height="125px" AllowPaging="True" AllowSorting="True"
                        PageSize="5" >
                        <Columns>
                            <asp:BoundField DataField="DateOccur" HeaderText="Login Date" 
                                SortExpression="DateOccur" />
                            <asp:BoundField DataField="TotalMinutesPlayed" HeaderText="Total Minutes" 
                                SortExpression="TotalMinutesPlayed" />
                        </Columns>
                        <AlternatingRowStyle BackColor="#EFEFEF" />
                    </asp:GridView>

Thanks!~

+2  A: 

If you can't sort it by editing the SQL itself, you can sort it programmatically by binding a DataView object to the datasource, specifying a Sort expression for the DataView, and then binding the DataGrid to the DataView object.

For a walkthrough of some example code, see here.

womp
+1  A: 

You could also use the Gridview.Sort method See Here.

thedugas
hi at what event should I put this Method? I tried it in DataBound and Sorting event but doesn't work :)
Sherwin Valdez
Try the page load event
thedugas