How to Default sort in GridView?

Posts   
 
    
Ad
User
Posts: 19
Joined: 21-Apr-2006
# Posted on: 03-Jun-2006 13:51:34   

Yes, in ASP.NET 2 you can get sorting within a GridView. Works like a charm for me.

But now I want to have one of the columns sorted by default. Even putting "ORDER BY [mycolumnname]" in the SQL query does not help ! confused

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39797
Joined: 17-Aug-2003
# Posted on: 03-Jun-2006 15:06:59   

You really have to give more info about the context this problem is in, like is this LLBLGen Pro related, do you use SqlDataSource or other object? simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Ad
User
Posts: 19
Joined: 21-Apr-2006
# Posted on: 03-Jun-2006 15:25:02   

Otis wrote:

You really have to give more info about the context this problem is in, like is this LLBLGen Pro related, do you use SqlDataSource or other object? simple_smile

No no... this is general chat.... wink not even LLBLGen related this time, just bare-bones GridView ASP.NET 2.0

Jez
User
Posts: 198
Joined: 01-May-2006
# Posted on: 03-Jun-2006 18:51:35   

If you specify an ORDER BY clause in your query then the gridview will automatically be sorted in that order.

You can also use the gridview's build in sort() method eg:


    MyGridView.Sort("Column1, Column2", SortDirection.Ascending);

Ad
User
Posts: 19
Joined: 21-Apr-2006
# Posted on: 04-Jun-2006 10:03:26   

Jez wrote:

If you specify an ORDER BY clause in your query then the gridview will automatically be sorted in that order.

You can also use the gridview's build in sort() method eg:


    MyGridView.Sort("Column1, Column2", SortDirection.Ascending);

Ehhh...ORDER BY works ???

How... where ? Like so: SelectCommand="SELECT * FROM [ViewClients] ORDER BY EnquiryDate DESC">

in <asp:SqlDataSource does NOT work for me.

I'll go and give the MyGridView.Sort a try.. thanks.

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005