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

Server-side data binding with nested RadListView

2 Answers 189 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Shannnon
Top achievements
Rank 1
Shannnon asked on 17 Jun 2012, 11:47 PM
I went through the demo of hierarchical RadListView, is there a way to do databinding in server-side instead of using SqlDataSource control?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 21 Jun 2012, 08:24 AM
Hi Shannnon,

As mentioned in the other forum thread, you can bind the listviews using their OnNeedDataSource server event. In it, you can cast sender to RadListView and get its NamingContainer which should be the parent RadListViewDataItem. From it, you can pick the ProductID and use it to query the database, something like:
protected void RadListView1_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
{
    RadListViewDataItem parentItem = (sender as RadListView).NamingContainer as RadListViewDataItem;
    string id = (parentItem.FindControl("HiddenField1") as HiddenField).Value;
    (sender as RadListView).DataSource= //query db for records having this ID
}

For this to work, declare an asp:HiddenField bound to the ProductID value.

Greetings,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Shannnon
Top achievements
Rank 1
answered on 23 Jun 2012, 12:02 AM
Thanks Tsvetina, your way works. 

Also, I found another way to do it. On parent RadListView's OnItemDataBound event, use RadListView rlv2 = e.Item.FindControl("NestedRadListView1") as RadListView to get the instance of the nested radlistview,  and use a hiddenField to get the childTable's query value and data bind the table to rlv2, and if there is one more nested listView in rlv2, use the same step that treats rlv2 as parent list view and specify the nested child view's datasource in rlv2's OnItemDataBound. this way, you can bind multiple nested radlistview in server side.

Tags
ListView
Asked by
Shannnon
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Shannnon
Top achievements
Rank 1
Share this question
or