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

Binding Object Properties to DetailTables

2 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AUE
Top achievements
Rank 1
AUE asked on 04 Mar 2011, 10:49 AM
Hello!!

This will be my first post hoping to get the answer as soon as possible...

With regards to the Subject, is there a way to Bind the Object Properties declaratively to the DetailTable of the Grid.

Lets assume this is my Object Structure

Class Person
         Property PersonName As String
         Property Hobbies As List(Of Hobby)
         Property Nationality As String
End Class

Class Hobby
         Property ID As Integer
         Property Description as String
End Class

And this is my Grid Structure

<telerik:RadGrid ID="myGrid" runat="server">
    <MasterTableView>
            <Columns>
                        <telerik:GridBoundColumn DataField="PersonName " />
                        <telerik:GridBoundColumn DataField="Nationality " />
            </Columns>
            <DetailTables>
                        <telerik:GridTableView Name="HobbyList">
                                    <Columns>
                                                            <telerik:GridBoundColumn DataField="Description" />
                                    </Columns>
                        </telerik:GridTableView>
            </DetailTables>
    </MasterTableView>
</telerik:RadGrid>

My Problem is that I want bind the whole Person object to the Grid and to the DetailTables. When I retrieve the Person object, I will the whole Person object, including all the properties [Hobbies].

Although I have an alternate solution to this, and that is to handle the DetailDataBind event and bind the Property to the Detail manually using CodeBehind.

Is there a way to do it declaratively? My purpose for this is to automate things and reduce the Codes behind.

Thank You..

2 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 09 Mar 2011, 06:41 PM
Hi,

You can find out how to specify a declarative hierarchy for the grid from this live demo. If you need to bind to your custom object one option is to use an ObjectDataSource control instead the shown SqlDataSource.  The markup settings are the same, you just need to specify a SelectMethod for the ObjectDataSource that takes one parameter passed through a session parameter as shown in the demo and retrieves the appropriate child entities for this parameter:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        SelectMethod="GetHobbies" TypeName="ObjectProvider">
            <SelectParameters>
                <asp:SessionParameter Name="PersonName" SessionField="PersonName" Type="int" />
            </SelectParameters>
    </asp:ObjectDataSource>

Public Shared Function GetHobbies(PersonName As Integer) As List(Of Hobbies)
    'return the hobbies collection for the particular person
End Function

Since you are binding to a custom hierarchy of objects you still have to provide some way to filter the child records based on the parent id and that is done in the GetHobbies method - so this is the minimum required code to achieve this. All the other hierarchy relations are specified declaratively.

Still another options is to use AutoGenerated Hierarchy, where the grid automatically generates the entire hierarchical structure and retrieves the relations between the items, but this is only supported for binding to DataSet with relations between the tables in it.


Best regards,
Marin
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
AUE
Top achievements
Rank 1
answered on 10 Mar 2011, 08:49 AM
Thanks Admin for your response.

I guess I have to make another Web Service to retrieve the object as DataSet, properties will be DataTable, and then set the Relationship between those table in the Business Layer, to be able to fully utilize the AutoGenerated Hierarchy and limit/minimize the Code-Behind.

Again, thank you for your support..
Tags
Grid
Asked by
AUE
Top achievements
Rank 1
Answers by
Marin
Telerik team
AUE
Top achievements
Rank 1
Share this question
or