RadListView and RadDataPager

2 posts, 0 answers
  1. Ben White
    Ben White avatar
    23 posts
    Member since:
    Feb 2010

    Posted 14 Jan 2011 Link to this post


    I am using the RadListView and RadDataPager but am getting some really bad results. I must be doing something very wrong. Please could you advise.

    I shall explain the intended outcome, the result and paste my code below.

    1. When the page first loads, a random selection of five database items is retrieved and the DataListView is databound. This happens in the page load event and only if the page is not a postback
    2. After this, users can select an item from a RadComboBox. Depending on the selection any number of items may be retrieved from the database
    3. Upon the server side event of RadComboBox firing, new database results are retrieved and the DataListView is rebound

    1. When the DataListView is rebound (step 3 above), the DataPager control only displays 2 new page buttons. The additional page buttons which should be there do not appear until after one of the buttons have been clicked. For example, if 3 pages of results are returned then the DataPager will show [1, 2], and if I click on 1 or 2 then it is refreshed and shows [1, 2, 3, n....]
    2. Another hideous problem is that the DataListView "OnPageIndexChanged" event goes into a loop on the server side (ouch!!!)

    Please could you advise as there are no examples of binding the DataListView and RadDataPager using anything other than a static datasource.

    <telerik:RadListView ID="RadListView1" CssClass="dlProfiles" Width="97%" OnPageIndexChanged="RadListView2_PageIndexChanged" AllowPaging="True" runat="server" AllowSorting="true" DataKeyNames="EngID"
    <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1" PageSize="6">
    <telerik:RadDataPagerButtonField FieldType="FirstPrev" />
    <telerik:RadDataPagerButtonField FieldType="Numeric" />
    <telerik:RadDataPagerButtonField FieldType="NextLast" />
    <telerik:RadDataPagerPageSizeField PageSizeText="Page size: " />
    <telerik:RadDataPagerGoToPageField CurrentPageText="Page: " TotalPageText="of" SubmitButtonText="Go" TextBoxWidth="15" />
    <div style="float: right">
    <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# Container.Owner.StartRowIndex+1%>" />
    <asp:Label runat="server" ID="TotalPagesLabel" Text="<%# Container.Owner.StartRowIndex+Container.Owner.PageSize %>" />
    <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.Owner.TotalRowCount%>" />
    <br />

    <asp:PlaceHolder ID="EmployeesContainer" runat="server" />
    <div class="EngProfileContainer">
    <div class="EngProfile_ImageContainer">
    <img src='<%# returnImage(DataBinder.Eval(Container.DataItem, "EngProfileImage").ToString())%>' width="80" />
    <p style="clear:both;height:0px;margin:3px 0px 0px 0px;">&nbsp;</p>
    <div class="EngProfileButton">
    <%# CheckDescriptionLinks(DataBinder.Eval(Container.DataItem, "engDescription").ToString(), DataBinder.Eval(Container.DataItem, "EngID").ToString())%>
    <p style="clear:both;height:0px;margin:3px 0px 0px 0px;">&nbsp;</p>
    <a class="viewEngineerProfile" href="engineerprofile.aspx?EngID=<%# DataBinder.Eval(Container.DataItem, "EngID")%>" target="_self">View full profile</a>
    <div class="EngProfileTextContainer">
    <p class="engname"><b><%# DataBinder.Eval(Container.DataItem, "EngName")%></b></p>
    <p class="engSkills"><%# DataBinder.Eval(Container.DataItem, "skillDescriptions")%></p>
    <%# CheckDescription(DataBinder.Eval(Container.DataItem, "engDescription").ToString(), DataBinder.Eval(Container.DataItem, "EngID").ToString())%>
    <div class="EngProfileCommentContainer">
    <p style="float:left;">Rating :</p>
    <p style="float:left;"><telerik:RadRating ID="RadRating1" Enabled="false" AutoPostBack="true" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "ratings")%>' ItemCount="5" SelectionMode="Continuous" Precision="Item" EnableEmbeddedSkins="false" Skin="Smaller" /></p>
    <p><a href="enginerreviews.aspx?engID=<%# DataBinder.Eval(Container.DataItem, "EngID")%>" target="_self"><%# DataBinder.Eval(Container.DataItem, "numofratings").ToString()%> Reviews</a></p>

    <p style="clear:both;height:0px;margin:0;">&nbsp;</p>

    protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
                IList<EngineerHelper.EngProfile> engProfiles = EngineerHelper.return_RandomEngineers(5);
                RadListView1.DataSource = engProfiles;
    protected void RadListView2_PageIndexChanged(object sender, RadListViewPageChangedEventArgs e)
                IList<EngineerHelper.EngProfile> engProfiles = EngineerHelper.return_RandomEngineers(0);
                RadListView1.DataSource = engProfiles;
        protected void returnEngineers(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
            IList<EngineerHelper.EngProfile> engProfiles = EngineerHelper.return_SelectedEngineers(EngineerHelper.engineerIDsBySkillGenre(Convert.ToInt16(e.Value)));
            RadListView1.DataSource = engProfiles;
  2. Tsvetina
    Tsvetina avatar
    2102 posts

    Posted 18 Jan 2011 Link to this post

    Hi Ben,

    Thank you for contacting us.

    I would recommend that you replace the simple data-binding that you are using with advanced data-binding through the NeedDataSource event. Using this approach, you can bind the listview to various datasources and you will not need to handle the rebinding on paging and other operations.

    You can see a live example of advanced data-binding at that address:
    Simple vs Advanced Binding

    Please, let us know if this does not fix the issue.

    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top