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

[Solved] Making a child objects properties filterable

1 Answer 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam Webb
Top achievements
Rank 1
Adam Webb asked on 03 Apr 2009, 10:56 AM
Hi there,
Apologies if this question is already documented, I couldn't find anything that would help me.
I am using the RadGrid, on a list of objects, "Request" (RadGrid1.DataSource = List<Request>). One property of "Request" is an object "Client". I don't want the object "Client" to be a column, but I would like for the property "Name" in "Client" to be shown. Ie. (String) Client.Name.

I managed to achieve this by Adding this on the ItemDataBound event as follows:
if (e.Item is GridDataItem) 
            { 
                int reqID; 
                String strReqID = ((GridDataItem)e.Item)["RequestID"].Text; 
                if (int.TryParse(strReqID, out reqID)) 
                { 
                    ((GridDataItem)e.Item)["Client"].Text = GetClientNameFromRequest(reqID); 
                } 
            } 

However, this appears to stop the column from being filterable. I would like for it to be possible to filter by Client.Name.

I realise it is not possible to set DataField="Client.Name". So I was wondering if there was another way I could achieve this?

Thanks in advance for any help!

FWIW I'm using WinXP, VS2008, .NET framework 3.5, and preferred language is C#.

1 Answer, 1 is accepted

Sort by
0
Accepted
Sebastian
Telerik team
answered on 06 Apr 2009, 03:31 PM
Hello Adam,

RadGrid for ASP.NET AJAX supports binding to sub-objects using declarative syntax with dots as demonstrated on this online demo:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/binding/defaultcs.aspx

Therefore, you can try the following signature for the DataField of the grid column:

DataField="Request.Client.Name"

Thus the filtering capability for that column should remain intact. Additional tips when binding RadGrid to custom collections you can find in this help topic.

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Adam Webb
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or