Server-side data binding with nested RadListView

3 posts, 0 answers
  1. Shannnon
    Shannnon avatar
    31 posts
    Member since:
    Oct 2010

    Posted 17 Jun 2012 Link to this post

    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. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 21 Jun 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shannnon
    Shannnon avatar
    31 posts
    Member since:
    Oct 2010

    Posted 22 Jun 2012 Link to this post

    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.

Back to Top