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

Set datapager index equal to dropdown index

1 Answer 86 Views
DataPager
This is a migrated thread and some comments may be shown as answers.
Daniel Elliott
Top achievements
Rank 1
Daniel Elliott asked on 14 Dec 2011, 09:56 PM
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.

MARKUP
<telerik:RadListView ID="RadListView1" runat="server" AllowPaging="True" DataSourceID="sqlActPlus" ItemPlaceholderID="ActionContainer" PageSize="1">
            <LayoutTemplate>
                <asp:PlaceHolder ID="ActionContainer" runat="server" />
                <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1" PageSize="1">
                    <Fields>
                        <telerik:RadDataPagerButtonField FieldType="FirstPrev" />
                        <telerik:RadDataPagerButtonField FieldType="Numeric" />
                        <telerik:RadDataPagerButtonField FieldType="NextLast" />
                        <telerik:RadDataPagerTemplatePageField>
                            <PagerTemplate>
                                <asp:DropDownList ID="drpActionList" DataSourceID="sqlActPlus" DataTextField="Action" DataValueField="Action" runat="server" AutoPostBack="true" OnSelectedIndexChanged="drpActionList_SelectedIndexChanged">
                                </asp:DropDownList>
                            </PagerTemplate>
                        </telerik:RadDataPagerTemplatePageField>
                        <telerik:RadDataPagerTemplatePageField>
                            <PagerTemplate>
                                <div style="float: right">
                                    <b>Action
                                        <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# Container.Owner.StartRowIndex+1%>" />
                                        to
                                        <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) %>" />
                                        of
                                        <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.Owner.TotalRowCount%>" />
                                        <br />
                                    </b>
                                </div>
                            </PagerTemplate>
                        </telerik:RadDataPagerTemplatePageField>
                    </Fields>
                </telerik:RadDataPager>
            </LayoutTemplate>
            <ItemTemplate>
                <fieldset>
                    <legend>Action</legend>
                    <table class="FullWidthTable">
                        <tbody>
                            <tr>
                                <th>
                                    Action Number
                                </th>
                                <th>
                                    Target Date
                                </th>
                                <th>
                                    Type
                                </th>
                            </tr>
                            <tr>
                                <td class="ReadOnlyValue">
                                    <%# Eval("ActionNo")%> 
                                </td>
                                <td class="ReadOnlyValue">
                                    <%# Eval("TargetMast", "{0:d}")%> 
                                </td>
                                <td class="ReadOnlyValue">
                                    <%# Eval("Type")%> 
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </fieldset>
            </ItemTemplate>
        </telerik:RadListView>

VB
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.

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 19 Dec 2011, 02:40 PM
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.

Greetings,
Tsvetina
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
Tags
DataPager
Asked by
Daniel Elliott
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or