Getting grid to sort

Posts   
 
    
JimFoye avatar
JimFoye
User
Posts: 656
Joined: 22-Jun-2004
# Posted on: 07-Dec-2004 15:02:50   

I put a collection on the form and bind to grid. I set the grid to sort and set SupportsSorting = true. At runtime I can click on the header and it posts back, but the records don't sort.

Here's my Page_Load:


            if (!IsPostBack)
            {
                regionsCollection1.GetMulti(null);
                RegionList.DataBind();
            }

At first I didn't wrap this in the check for postback, then I put that in there, but it didn't help (but my data still shows, so I guess I should be doing it anyway).

What is SortClauses for? Should I be setting that to something?

Jim

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Dec-2004 15:44:30   

When the page is rendered, your collection is gone, as the page object is destroyed by asp.net.

So when you get a postback, either the grid knows the data and sorts it internally, or you have to bind the data again and sort manually using the Sort() method of the entity collection. To keep the collection around, use teh viewstate or preferrably, the session object.

Frans Bouma | Lead developer LLBLGen Pro
JimFoye avatar
JimFoye
User
Posts: 656
Joined: 22-Jun-2004
# Posted on: 07-Dec-2004 16:22:27   

OK, so it doesn't happen automagically, I need to cache my object, then sort it in the event handler that gets fired when the user clicks on the column header, and rebind?

That's fine, though I'm curious what the point of the SupportsSorting property is. And SortClauses.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Dec-2004 16:41:19   

JimFoye wrote:

OK, so it doesn't happen automagically, I need to cache my object, then sort it in the event handler that gets fired when the user clicks on the column header, and rebind?

Yes.

That's fine, though I'm curious what the point of the SupportsSorting property is. And SortClauses.

SupportsSorting is an IBindingList property, used by winforms controls mostly. SortClauses is a property used to fetch the collection using GetMulti(), set by entity.SetCollectionParameters<Fieldname>() , so you can specify how myCustomer.Orders is fetched for example

Frans Bouma | Lead developer LLBLGen Pro