RadDataPager findcontrol

2 posts, 0 answers
  1. Noel Tam
    Noel Tam avatar
    2 posts
    Member since:
    Apr 2004

    Posted 02 Jan 2011 Link to this post

    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Feb 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top