How to manager OnNeedDataSource for a Listview inside other listview

5 posts, 0 answers
  1. Blas
    Blas avatar
    55 posts
    Member since:
    Dec 2007

    Posted 26 Aug 2010 Link to this post

    Hello

    I'm building a blog and each post corresponds to an item in the ListView that is bounded to a sql datasource. Each post is identify for a unique record number.

    For each item in the listview I need to show other listview inside the item containing the attached files for this particular post. The records for this second listview should be obtained with "OnNeedDataSource" because this list is builded exploring the directory where the attached files are stored.

    Is it possible to do that? Anyone has an example? How can I identify the record number of the post in this event routine.

    Thanks in advance


  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 31 Aug 2010 Link to this post

    Hello Roberto,

    In order to achieve the requested functionality you may use nested ListView's NamingContainer, which in this case should be parent listView's RadListViewDataItem to access the appropriate DataKeyValue. Similar to the following:

    protected void FilesListView_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
    {
        var innerListView = ((RadListView)sender);
        var parentListViewItem = innerListView.NamingContainer as RadListViewDataItem;
        var parentPostId = (int)parentListViewItem.GetDataKeyValue("PostId");
        innerListView.DataSource = GetFilesByPostId(parentPostId);
    }


    and simple lyout:
    <telerik:RadListView runat="server" ID="PostListView" DataKeyNames="PostId">
        <ItemTemplate>
            <%--....--%>
            <telerik:RadListView ID="FilesListView" runat="server" 
                OnNeedDataSource="FilesListView_NeedDataSource">
                <ItemTemplate>
                    <%--....--%>
                </ItemTemplate>
            </telerik:RadListView>
        </ItemTemplate>
    </telerik:RadListView>

    All the best,
    Rosen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Blas
    Blas avatar
    55 posts
    Member since:
    Dec 2007

    Posted 06 Sep 2010 Link to this post

    Hello Rosen,

    Thank you very much for your answer. It works fine!!!

    Greetings
  5. Carlo
    Carlo avatar
    6 posts
    Member since:
    Oct 2010

    Posted 22 Oct 2010 Link to this post

    I ran into a similar issue (but with a RadGrid inside the RadListview's itemtemplate instead of another list view), if I try the above code:

    var parentPostId = (int)parentListViewItem.GetDataKeyValue("PostId");

    This always seems to yield the previous datakey value (i.e. the item displayed last before the current item displayed).
    This happens when I click the page buttons on the RadPager of the RadListView.

    Example:

    Let's say I was viewing the 4th Item with a datakeyvalue of 4, on the initial call to RadGrid_NeedDataSource, the code
    above returns 4. If I then click the radlistview page button for the 9th Item with a datakeyvalueof 9, in the second call to RadGrid_NeedDataSource the code above returns 4 again, if I then naviate back to the 4th item in the third call to
    RadGrid_NeedDataSource the code above returns 9 etc.

    Did I setup something wrong?

    -Carlo
  6. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 25 Oct 2010 Link to this post

    Hello Carlo,

    I have replayed to your post on the following thread:
    http://www.telerik.com/community/forums/aspnet-ajax/listview/radgrid-inside-radlistview-problem.aspx

    Regards,
    Nikolay
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017