RadDataPager FindControl

6 posts, 0 answers
  1. Chris
    Chris avatar
    66 posts
    Member since:
    Sep 2008

    Posted 11 Nov 2009 Link to this post

    Hi,

    I'm trying to put a DropDownList for sort order in my RadDataPager Fields.  (RadDataTemplatePageField).

    I'd like to use this for a sort order in my own custom call to my stored procedure, but I can't figure out how to get the value of the drop down list since it's inside the Page Template.

    Does anyone know how to use FindControl to get the DropDownList control?

    Here's a snippet of what I'm doing:

        <asp:Panel ID="Panel3" DefaultButton="btSearch" runat="server" CssClass="pnlSection"
            <telerik:RadListView ID="rlvItems" runat="server" 
                ItemPlaceholderID="ItemContainer" AllowCustomPaging="true" 
                EnableViewState="false" AllowPaging="true" OnNeedDataSource="rlvItems_NeedDataSource" 
                PageSize="10" 
            > 
                <LayoutTemplate> 
                <asp:Button ID="btTest" runat="server" /> 
                <div style="float:left; width:100%; padding: 4px 0px 4px 0px; font-family: Helvetica, Verdana, Arial ; font-size: 9pt;"
                <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="rlvItems" Width="100%" 
                    PageSize="10"
                    <Fields> 
                        <telerik:RadDataPagerButtonField FieldType="FirstPrev" /> 
                        <telerik:RadDataPagerButtonField FieldType="Numeric" /> 
                        <telerik:RadDataPagerButtonField FieldType="NextLast" /> 
                        <telerik:RadDataPagerPageSizeField PageSizeText="Page size: " /> 
                        <telerik:RadDataPagerTemplatePageField> 
                            <PageTemplate> 
                                <div> 
                                    <asp:DropDownList ID="ddlSortType" runat="server" Width="160px" AutoPostBack="true"
                                        <asp:ListItem Text="Most Purchased" Value="PD"></asp:ListItem> 
                                        <asp:ListItem Text="Recently Uploaded" Value="CD"></asp:ListItem> 
                                        <asp:ListItem Text="Most Rated/Reviewed" Value="TD"></asp:ListItem> 
                                        <asp:ListItem Text="Highest Rated" Value="RD"></asp:ListItem> 
                                        <asp:ListItem Text="Artist Name" Value="OA"></asp:ListItem> 
                                        <asp:ListItem Text="Longest by Time" Value="DD"></asp:ListItem> 
                                        <asp:ListItem Text="Shortest by Time" Value="DA"></asp:ListItem> 
                                    </asp:DropDownList> 
                                </div> 
                            </PageTemplate> 
                        </telerik:RadDataPagerTemplatePageField> 
     

    Thanks!
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 11 Nov 2009 Link to this post

    Hello Chris,

    You can access the dropdown directly through the first sender argument passed in its OnSelectedIndexChanged server event handler. See how this is done for the dropdown in the layout template of the first RadListView instance on this example:

    http://demos.telerik.com/aspnet-ajax/listbox/examples/default/defaultcs.aspx

    Thus you can fetch the selected value from it without the need to locate the actual dropdown inside the RadDataPager with FindControl(id) method.

    Kind regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chris
    Chris avatar
    66 posts
    Member since:
    Sep 2008

    Posted 11 Nov 2009 Link to this post

    Hi Sebastian,

    I couldn't figure out what you were referring in the link to the Listbox examples....

    This example helped me a bit after checking the examples a bit more:
    http://demos.telerik.com/aspnet-ajax/listview/examples/paging/raddatapager/defaultcs.aspx

    and then I used the example from Rick Strahl to find it:
    http://west-wind.com/Weblog/posts/5127.aspx

    Here's what ended up working for me:
            string sortType = null;  
            RadDataPager dataPager = (RadDataPager)rlvItems.FindControl("RadDataPager1");  
            if (dataPager != null)  
            {  
                DropDownList ddl = FindControlRecursive(dataPager, "ddlSortType"as DropDownList;  
                if (ddl != null)  
                {  
                    sortType = ddl.SelectedValue;  
                }  
            }  
     

    Maybe you were referring to this?
    http://demos.telerik.com/aspnet-ajax/listview/examples/firstlook/defaultcs.aspx

    Anyway, the customer wants the sort in the Pager area, so this seems to work for what I need to do.

    Thanks!
  5. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 11 Nov 2009 Link to this post

    Hi Chris,

    Please excuse me for the mistake - indeed I have in mind the first look demo of RadListView you pointed out. I am glad that you find a solution which is in par with your preferences.

    Best regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Pierre
    Pierre avatar
    212 posts
    Member since:
    Apr 2007

    Posted 16 Nov 2009 Link to this post

    What about the TemplateLayout?

    I need to change the text of the button (next, previous, ... ) according to language selection. How I can acces to this:
    I try findcontrol diectly on the ListView without success.
                        <div style="float: left; margin-left: 30%;">  
                            <asp:Button runat="server" ID="btnFirst" CommandName="Page" CommandArgument="First" 
                                Text="First" Enabled="<%#Container.CurrentPageIndex > 0 %>" /> 
                            <asp:Button runat="server" ID="btnPrev" CommandName="Page" CommandArgument="Prev" 
                                Text="Prev" Enabled="<%#Container.CurrentPageIndex > 0 %>" /> 
                            <span style="vertical-align: top; position: relative; top: 4px">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 %>" /> 
                            <asp:Button runat="server" ID="btnLast" CommandName="Page" CommandArgument="Last" 
                                Text="Last" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" /> 
                        </div> 
  7. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 17 Nov 2009 Link to this post

    Hello Pierre,

    If you use the pager fields with predefined elements/controls structure, you can locate the elements/controls in them by their ids invoking the FindControl(id) method for the RadDataPager instance. The ids of each pager field are listed in this documentation topic.

    In case you use RadDataPagerTemplateField as I assume is in your case (judging from the code snippet you pasted), you can get reference to the asp Buttons by their explicitly set ids again with the FindControl(id) method called for RadDataPager.

    Kind regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017