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

RadListView and RadDataPager

1 Answer 171 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Ben White
Top achievements
Rank 1
Ben White asked on 14 Jan 2011, 06:17 PM
Hi,

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

Issues:
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"
ItemPlaceholderID="EmployeesContainer">
<LayoutTemplate>
<telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1" PageSize="6">
<Fields>
<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" />
<telerik:RadDataPagerTemplatePageField>
<PagerTemplate>
<div style="float: right">
<b>Items
<asp:Label runat="server" ID="CurrentPageLabel" Text="<%# Container.Owner.StartRowIndex+1%>" />
to
<asp:Label runat="server" ID="TotalPagesLabel" Text="<%# Container.Owner.StartRowIndex+Container.Owner.PageSize %>" />
of
<asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.Owner.TotalRowCount%>" />
<br />
</b>
</div>
</PagerTemplate>
</telerik:RadDataPagerTemplatePageField>
</Fields>
</telerik:RadDataPager>

<asp:PlaceHolder ID="EmployeesContainer" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<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>
</div>
<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>
<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>
</div>



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

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

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 18 Jan 2011, 02:22 PM
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.

Regards,
Tsvetina
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.
Tags
ListView
Asked by
Ben White
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or