Set datapager index equal to dropdown index

2 posts, 0 answers
  1. Daniel Elliott
    Daniel Elliott avatar
    4 posts
    Member since:
    Jul 2009

    Posted 14 Dec 2011 Link to this post

    I have a dropdown list in a pager template. I am attempting to set the page index of a listview using the dropdownlist in the datapager to allow the customer to jump to a record using more meaningful text than a page number. The page size will always be 1.

    <telerik:RadListView ID="RadListView1" runat="server" AllowPaging="True" DataSourceID="sqlActPlus" ItemPlaceholderID="ActionContainer" PageSize="1">
                    <asp:PlaceHolder ID="ActionContainer" runat="server" />
                    <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1" PageSize="1">
                            <telerik:RadDataPagerButtonField FieldType="FirstPrev" />
                            <telerik:RadDataPagerButtonField FieldType="Numeric" />
                            <telerik:RadDataPagerButtonField FieldType="NextLast" />
                                    <asp:DropDownList ID="drpActionList" DataSourceID="sqlActPlus" DataTextField="Action" DataValueField="Action" runat="server" AutoPostBack="true" OnSelectedIndexChanged="drpActionList_SelectedIndexChanged">
                                    <div style="float: right">
                                            <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# Container.Owner.StartRowIndex+1%>" />
                                            <asp:Label runat="server" ID="TotalPagesLabel" Text="<%# IIF(Container.Owner.TotalRowCount > (Container.Owner.StartRowIndex+Container.Owner.PageSize), Container.Owner.StartRowIndex+Container.Owner.PageSize, Container.Owner.TotalRowCount) %>" />
                                            <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.Owner.TotalRowCount%>" />
                                            <br />
                        <table class="FullWidthTable">
                                        Action Number
                                        Target Date
                                    <td class="ReadOnlyValue">
                                        <%# Eval("ActionNo")%> 
                                    <td class="ReadOnlyValue">
                                        <%# Eval("TargetMast", "{0:d}")%> 
                                    <td class="ReadOnlyValue">
                                        <%# Eval("Type")%> 

    Protected Sub drpActionList_SelectedIndexChanged(ByVal sender As DropDownList, ByVal e As System.EventArgs)
        Dim dataPager As Telerik.Web.UI.RadDataPager = DirectCast(RadListView1.FindControl("RadDataPager1"), Telerik.Web.UI.RadDataPager)
        If dataPager IsNot Nothing Then
             dataPager.PageIndex = sender.SelectedIndex ' I realize this line doesn't work
        End If
    End Sub

    The text value of the dropdown list is similar to "XXB123" and "IMO45687" and isn't always sequential. That is why I want to use the selected index.
  2. Tsvetina
    Tsvetina avatar
    1862 posts

    Posted 19 Dec 2011 Link to this post

    Hi Daniel,

    You could try the following code which fires a Page command inside the RadDataPager, using as an argument the selected index of the dropdown:
    DropDownList ddl = sender as DropDownList;
    RadDataPager pager = ddl.NamingContainer.NamingContainer as RadDataPager;
    pager.FireCommand("Page", ddl.SelectedIndex.ToString());

    I hope it helps.

    the Telerik team
    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 their blog feed now
  3. DevCraft R3 2016 release webinar banner
Back to Top