This is a migrated thread and some comments may be shown as answers.

[Solved] What's the SortExpression on a nested object?

5 Answers 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
diggityDawg
Top achievements
Rank 1
diggityDawg asked on 14 May 2008, 06:27 PM
I've got a RadGrid that uses an object collection as it's datasource.  Each object/row has it's own collection of objects.  When I display the grid I just display the first item in the sub-collection.  So, for example, I have a grid of people.  Each row is a person.  Each person has a collection of addresses.  In the "Address" column I have a Label, which I use to put the first address in the collection of addresses (using the OnItemCreated event).  How do I specify the SortExpression so that I can sort this grid on the address displayed? 

Here's my OnItemCreated method:
protected void RadGrid_ItemCreated(object sender, GridItemEventArgs e)     
{     
    Person p = (Person) e.Item.DataItem;     
    if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)     
    {     
        Label lblAddress = (Label) e.Item.Cells[4].FindControl("lblAddress");     
        if (p.Addresses != null)     
        {     
            if (p.Addresses.Count > 0)     
            {     
                Address address = p.Addresses[0];     
                lblAddress.Text = address.StreetNumber.Trim() + " " + address.StreetName.Trim() + " " +     
                                  address.AptNumber.Trim();     
            }     
        }     
    }     
}   

Thanks!

Eddie

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 May 2008, 07:36 AM
Hi,

Are you using a TemplateColumn? Go through the following article which explains how to attain sorting with GridTemplateColumns.
Sorting for GridHyperLinkColumn/GridTemplateColumn

Thanks
Shinu.
0
diggityDawg
Top achievements
Rank 1
answered on 15 May 2008, 03:02 PM
Hi Shinu,

Thanks for your reply.  I am using a TemplateColumn.  I did see that article, but it doesn't really address my issue.  In my TemplateColumn I have a Label control.  In my code I build a string out of several data fields in the object, then I set the Text property of the Label to the string I just built.  To make matters more complicated, the object I am using is a nested object within the main DataItem for the row.  So what field do I use as the Sort Expression.  If you look at my code you'll see that I am using address[0].StreetNumber, address[0].StreetName and address[0].AptNumber.  But I can't put those into the SortExpression field.  I tried building a local variable called "Address" and using that for the SortExpression, but it says there is no field with the name "Address" when I try to execute the code.

Any other ideas I can try?

Thanks,

eddie
0
SSDApplications
Top achievements
Rank 2
answered on 27 May 2008, 05:29 PM
Any resolution for this yet?  I still can't get my grid to sort...  BTW, I am the same as original poster, just registered with different username...

Eddie
0
Sebastian
Telerik team
answered on 28 May 2008, 06:49 AM
Hi Eddie,

Unfortunately setting SortExpression for template/hyperlink columns which point to properties of sub-objects is not supported in the present version of RadGrid. A possible workaround is explained in this forum thread:

http://www.telerik.com/community/forums/thread/b311D-ehght.aspx

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Juan Angel
Top achievements
Rank 1
Veteran
answered on 20 Apr 2009, 11:37 PM
Tags
Grid
Asked by
diggityDawg
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
diggityDawg
Top achievements
Rank 1
SSDApplications
Top achievements
Rank 2
Sebastian
Telerik team
Juan Angel
Top achievements
Rank 1
Veteran
Share this question
or