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

RadDataPager findcontrol

1 Answer 62 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Noel Tam
Top achievements
Rank 1
Noel Tam asked on 02 Jan 2011, 09:54 AM
hi all
I have a list view and RadDataPager . Inside the RadDataPager , I have a dropdownlist control, I would like get the value of the dropdownlist control. I try ctype(RadDataPager.findcontrol("dropdownlist"), dropdownlist).selectedvalue but failed. 

how can I get the find the control inside the RadDataPager. Thanks

Regards,
Tam

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Feb 2011, 12:27 PM
Hello Noel,

Give a try with the following code snippet to get the control inside RadDataPager.
ASPX:
<telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1"
   .   .    .   .   .   .
        <telerik:RadDataPagerTemplatePageField>
            <PagerTemplate>
                <div style="float: right">
                    <b>Items
                        <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# Container.Owner.StartRowIndex+1%>" />
                        to
                        <asp:Label runat="server" ID="TotalPagesLabel" Text="<%# Container.Owner.StartRowIndex+Container.Owner.PageSize %>" />
                        of
                        <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.Owner.TotalRowCount%>" />
                        <br />
                        <br />
                        combo:
                        <asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSource1" DataTextField="Fieldname"
                            DataValueField="Fieldname" runat="server">
                        </asp:DropDownList>
                    </b>
                </div>
            </PagerTemplate>
        </telerik:RadDataPagerTemplatePageField>
    </Fields>
</telerik:RadDataPager>

C#:
protected void Page_Load(object sender, EventArgs e)
    {
        string sortType = null;
        RadDataPager dataPager = (RadDataPager)RadListView1.FindControl("RadDataPager1");
        if (dataPager != null)
        {
            DropDownList ddl = FindControlRecursive(dataPager, "DropDownList1") as DropDownList;
            if (ddl != null)
            {
                sortType = ddl.SelectedValue;
            }
        
    }
    public static Control FindControlRecursive(Control Root, string Id)
    {
        if (Root.ID == Id)
            return Root;
        foreach (Control Ctl in Root.Controls)
        {
            Control FoundCtl = FindControlRecursive(Ctl, Id);
            if (FoundCtl != null)
                return FoundCtl;
        }
        return null;
    }

Thanks,
Princy.
Tags
ListView
Asked by
Noel Tam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or