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

RadDataPager FindControl

5 Answers 174 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 11 Nov 2009, 06:55 AM
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!

5 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 11 Nov 2009, 12:20 PM
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.
0
Chris
Top achievements
Rank 1
answered on 11 Nov 2009, 02:38 PM
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!
0
Sebastian
Telerik team
answered on 11 Nov 2009, 03:12 PM
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.
0
Pierre
Top achievements
Rank 2
Iron
Iron
answered on 16 Nov 2009, 08:57 PM
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> 
0
Sebastian
Telerik team
answered on 17 Nov 2009, 09:51 AM
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.
Tags
ListView
Asked by
Chris
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Chris
Top achievements
Rank 1
Pierre
Top achievements
Rank 2
Iron
Iron
Share this question
or