ListView of UserControls, how to access UserControls on Page Command

3 posts, 0 answers
  1. Patrick
    Patrick avatar
    29 posts
    Member since:
    May 2011

    Posted 18 Oct 2013 Link to this post

     I have a Radlistview of my own UserControls.

     Inside the RadListview i have some paging buttons. Either when the ItemCommand is fired (and it equals("Page")) or when the PageIndexChanged event is fired, i need to access my UserControls on this page.

    The why: currently, each of my user controls have a Save button. That works fine. however, my client would now like all of my user controls to be saved when they hit any of the paging buttons.
    How can i do that? I can't figure out how to access my DataItems (UserControlClass) from within either the PageIndexChanged or ItemCommand Events - partly because the paging buttons are themselves not a Usercontrol.

    <telerik:RadListView ID="lvWorkGroups" runat="server"
            DataKeyNames="ID, Name"
            AllowPaging="True" PageSize="1"
                    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                    <div class="workGroup2" style="text-align:center">
                        <div style="margin:auto;">
                            <asp:Button runat="server" ID="btnFirst" CommandName="Page" CommandArgument="First"
                                Text="First" Enabled="<%#Container.CurrentPageIndex > 0 %>" CausesValidation="false"></asp:Button>
                            <asp:Button runat="server" ID="btnPrev" CommandName="Page" CommandArgument="Prev"
                                Text="Prev" Enabled="<%#Container.CurrentPageIndex > 0 %>" CausesValidation="false"></asp:Button>
                            <span style="vertical-align: middle; line-height:22px; display:inline-block;">Page
                                <%#Container.CurrentPageIndex + 1 %>
                                <%#Container.PageCount %></span>
                            <asp:Button runat="server" ID="btnNext" CommandName="Page" CommandArgument="Next"
                                Text="Next" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" CausesValidation="false">
                            <asp:Button runat="server" ID="btnLast" CommandName="Page" CommandArgument="Last"
                                Text="Last" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" CausesValidation="false">
               <uc1:InspectionWorkGroup ID="InspectionWorkGroup1" runat="server" OnworkGroupSaved="wg_workGroupSaved"/>
  2. Patrick
    Patrick avatar
    29 posts
    Member since:
    May 2011

    Posted 21 Oct 2013 Link to this post

    anyone, have any ideas?
  3. Eyup
    Eyup avatar
    4072 posts

    Posted 23 Oct 2013 Link to this post

    Hi Patrick,

    Since you have only 1 item on the page at a time, it is safe to use the following approach to access the inner content of the user control:
    protected void lvWorkGroups_ItemCommand(object sender, RadListViewCommandEventArgs e)
        if (e.CommandName == RadListView.PageCommandName)
            InspectionWorkGroup workGroup = lvWorkGroups.Items[0].FindControl("InspectionWorkGroup1") as InspectionWorkGroup;
            // execute custom logic to update the work group

    Hope this helps. Please give it a try and let me know if it works for you.

    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 the blog feed now.
Back to Top