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!

    ASP:
    <telerik:RadListView ID="RadGrid_Bookmarks" runat="server"
                    OnNeedDataSource="RadGrid_Bookmarks_NeedDataSource"
                     EnableViewState="true" ItemPlaceholderID="phRadListView" >
                     <LayoutTemplate>
                    
                   <telerik:RadDataPager ID="radPager1"  runat="server" Skin="Windows7"   OnPreRender="radPager_PreRender"   OnInit="radPager_Init"  >
                        <Fields>
                        <telerik:RadDataPagerTemplatePageField HorizontalPosition="LeftFloat">
                            <PagerTemplate>
                                <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"  />
                                </div>
                            </PagerTemplate>
                        </telerik:RadDataPagerTemplatePageField>
                         <telerik:RadDataPagerButtonField FieldType="NextLast" HorizontalPosition="RightFloat" />
                          <telerik:RadDataPagerButtonField FieldType="Numeric" HorizontalPosition="RightFloat" />
                        <telerik:RadDataPagerButtonField FieldType="FirstPrev" HorizontalPosition="RightFloat" />
        </Fields>        
    </telerik:RadDataPager>



    Code Behind:
    protected void ddlDays_SelectedIndexChanged(object sender, EventArgs e)
            {
                RadGrid_Bookmarks.Rebind();
            }
     
            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
    Admin
    Kostadin avatar
    1711 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. 

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