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

ListView of UserControls, how to access UserControls on Page Command

2 Answers 146 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 18 Oct 2013, 02:23 PM
Hi,
 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"
        OnItemDataBound="lvWorkGroups_ItemDataBound"
        onneeddatasource="lvWorkGroups_NeedDataSource"
        AllowPaging="True" PageSize="1"
        ItemPlaceholderID="PlaceHolder1"
         onpageindexchanged="lvWorkGroups_PageIndexChanged"
         onpagesizechanged="lvWorkGroups_PageSizeChanged"
         ondatabound="lvWorkGroups_DataBound"
          onitemcommand="lvWorkGroups_ItemCommand">
         
        <LayoutTemplate>
                <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 %>
                            of
                            <%#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>
                        <asp:Button runat="server" ID="btnLast" CommandName="Page" CommandArgument="Last"
                            Text="Last" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" CausesValidation="false">
                        </asp:Button>
                    </div>
                </div>
        </LayoutTemplate>
 
        <ItemTemplate>
           <uc1:InspectionWorkGroup ID="InspectionWorkGroup1" runat="server" OnworkGroupSaved="wg_workGroupSaved"/>
        </ItemTemplate>
    </telerik:RadListView>

2 Answers, 1 is accepted

Sort by
0
Patrick
Top achievements
Rank 1
answered on 21 Oct 2013, 04:26 PM
anyone, have any ideas?
0
Eyup
Telerik team
answered on 23 Oct 2013, 08:23 AM
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.

Regards,
Eyup
Telerik
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.
Tags
ListView
Asked by
Patrick
Top achievements
Rank 1
Answers by
Patrick
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or