Sorting an ObjectDataSource

Posts   
 
    
larkydoo
User
Posts: 45
Joined: 30-Jun-2008
# Posted on: 21-Apr-2010 23:31:45   

I'm trying to use an ObjectDataSource to populate a DropDownList. The code for the ods is:

        <asp:ObjectDataSource ID="odsStates" runat="server" SelectMethod="GetMultiAsDataTable" TypeName="xxx.xxx.xxx.CollectionClasses.StateCollection">
            <SelectParameters>
                <asp:Parameter DefaultValue="null" Name="selectFilter" Type="Object" />
                <asp:Parameter DefaultValue="0" Name="maxNumberOfItemsToReturn" Type="Int64" />
                <asp:Parameter DefaultValue="null" Name="sortClauses" Type="Object" />
            </SelectParameters>
        </asp:ObjectDataSource>

Is there anything I can put in the DefaultValue of the sortClauses parameter to sort by StateName? Also, is there any way to create a filter, e.g. StateID <> 99?

I tried the LLBLGenProDataSource as well and there's nothing obvious in that control to do what I want to do.

Thanks.

Laurie

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Apr-2010 07:07:36   

larkydoo wrote:

I tried the LLBLGenProDataSource as well and there's nothing obvious in that control to do what I want to do.

Hi Laurie, What did you try with LLBLGenProDataSource. You only have to specify the sorter in code (Page_Load for instance):

myLLBLGenDataSource.SorterToUse = ...
David Elizondo | LLBLGen Support Team
larkydoo
User
Posts: 45
Joined: 30-Jun-2008
# Posted on: 22-Apr-2010 16:33:14   

I'm wanting do do it all in the tag if possible, since I have to do this in about five places in my application. If I have to do it in my code, I may as well not use an ods and just generate a sorted collection and apply that to the dropdownlist, no? Is there not a way to do it as part of the tag, either with the LLBLGenProDataSource or the ObjectDataSource?

Thanks.

Laurie

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Apr-2010 06:04:50   

As far as I know it's not possible declaratively in ods: http://msdn.microsoft.com/en-us/library/57hkzhy5.aspx

LLBLGenProDataSource inherits from ods, so its the same. This is maybe because the sort expression can be complex. That would be difficult to represent in the tags.

David Elizondo | LLBLGen Support Team
larkydoo
User
Posts: 45
Joined: 30-Jun-2008
# Posted on: 23-Apr-2010 21:43:50   

Okay, thanks. I created a custom static method that returns the exact data I want in the order I want it and am using that in the ods. Works great!