ListView Rebind Pager

2 posts, 0 answers
  1. Angie
    Angie avatar
    101 posts
    Member since:
    Jan 2008

    Posted 31 Jan 2013 Link to this post

    Hello.  I am using a dropdown in combination with a ListView/DataPager.  The dropdownlist does a postback which rebinds the ListView.

    I problem is that I'm showing/hiding the RadDataPager using the RadDataPager on_prerender event, which does not get called when the ListView is rebound.

    How can I cause this event to be called when I rebind my ListView?   Thanks!

    <telerik:RadListView ID="RadGrid_Bookmarks" runat="server"
                     EnableViewState="true" ItemPlaceholderID="phRadListView" >
                   <telerik:RadDataPager ID="radPager1"  runat="server" Skin="Windows7"   OnPreRender="radPager_PreRender"   OnInit="radPager_Init"  >
                        <telerik:RadDataPagerTemplatePageField HorizontalPosition="LeftFloat">
                                <div style="float: right;color:#666666;">
                                    Displaying items <asp:Label runat="server" ID="PageItemFromLabel"  /> to <asp:Label runat="server" ID="PageItemToLabel"  /> of <asp:Label runat="server" ID="TotalItemsLabel"  />
                         <telerik:RadDataPagerButtonField FieldType="NextLast" HorizontalPosition="RightFloat" />
                          <telerik:RadDataPagerButtonField FieldType="Numeric" HorizontalPosition="RightFloat" />
                        <telerik:RadDataPagerButtonField FieldType="FirstPrev" HorizontalPosition="RightFloat" />

    Code Behind:
    protected void ddlDays_SelectedIndexChanged(object sender, EventArgs e)
            protected void RadGrid_Bookmarks_NeedDataSource(object source, RadListViewNeedDataSourceEventArgs e)
        DataSet dsBookmarks = GetPostsByUser(UserID, uID, SiteID, int.Parse(ddlDays.SelectedValue), RadGrid_Bookmarks.CurrentPageIndex + 1);
        RadGrid_Bookmarks.VirtualItemCount = int.Parse(dsBookmarks.Tables[0].Rows[0]["totalRec"].ToString());
        RadGrid_Bookmarks.PageSize = 50;
        RadGrid_Bookmarks.DataSource = dsBookmarks.Tables[1];
            protected void radPager_PreRender(object sender, EventArgs e)
                RadDataPager rdp = (RadDataPager)sender;
                ((Label)rdp.Controls[0].FindControl("PageItemFromLabel")).Text = (rdp.StartRowIndex + 1).ToString();
                ((Label)rdp.Controls[0].FindControl("PageItemToLabel")).Text = ((rdp.TotalRowCount < (rdp.StartRowIndex + rdp.PageSize)) ? rdp.TotalRowCount : rdp.StartRowIndex + rdp.PageSize).ToString();
                ((Label)rdp.Controls[0].FindControl("TotalItemsLabel")).Text = rdp.TotalRowCount.ToString();
                if (rdp.TotalRowCount <= rdp.PageSize)
                    rdp.Visible = false;
            protected void radPager_Init(object sender,EventArgs e)
                RadDataPager rdp = (RadDataPager)sender;
                rdp.PageSize = 50;
  2. Kostadin
    Kostadin avatar
    1689 posts

    Posted 05 Feb 2013 Link to this post

    Hi Angie,

    When you hide the RadDataPager and rebind the ListView the PreRender event will not be fired because the pager is not rendered on the page. A possible approach is to implement the same logic on Page_PreRender event. In this case the code will be executed every time. 

    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