+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Widget Template Paging Controls

Widget Template Paging Controls

5 posts, 1 answered
  1. Chris
    Chris avatar
    63 posts
    Registered:
    05 Jan 2011
    04 Feb 2011
    Link to this post
    I've created a new custom control to display specific Generic content.  My display code for this is listed below.  My question is, I'm using a DataPager to limit the results per page, but when I click Next or Page 2, it tries to go to default.aspx.  How do I change it to use the current page but show the proper data?

    <telerik:RadListView ID="KBList" ItemPlaceholderID="ItemsContainer" runat="server"
        EnableEmbeddedSkins="False" EnableEmbeddedBaseStylesheet="False"
        AllowPaging="True">
        <LayoutTemplate>
            <sf:ContentBrowseAndEditToolbar ID="MainBrowseAndEditToolbar" runat="server" Mode="Add"></sf:ContentBrowseAndEditToolbar>
            <asp:PlaceHolder ID="ItemsContainer" runat="server" />
        </LayoutTemplate>
        <ItemTemplate>
            <div id="main_body_listing">
                <div class="listing_title2"><asp:HyperLink ID="KBTitle" runat="server"/></div>
                <asp:Label ID="KBDescription" runat="server" Text="Label"></asp:Label>
            </div>
        </ItemTemplate>
    </telerik:RadListView>
     
    <div id="bottomPagingContent" clientidmode="Static" style="height:35px;" runat="server">
        <div style="float:right;">
            <asp:DataPager ID="kbBottomPager" PagedControlID="KBList" PageSize="5" runat="server">
                <Fields>
                    <asp:NextPreviousPagerField FirstPageText="<<" ShowFirstPageButton="True"
                        ShowNextPageButton="False" ShowPreviousPageButton="False" ButtonType="Button" />
                    <asp:NumericPagerField ButtonType="Link" Visible="true" />
                    <asp:NextPreviousPagerField LastPageText=">>" ShowLastPageButton="True"
                        ShowNextPageButton="False" ShowPreviousPageButton="False" ButtonType="Button" />
                </Fields>
            </asp:DataPager>
        </div>
    </div>
  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    15 Jul 2016
    08 Feb 2011
    Link to this post
    Hi Chris,

    In your custom control, how  do you bind the RadListView? We don't see the DataSourceID set in the template. Can you send us the full code of your custom control, so we could investigate the problem locally?

    Also you see some examples of using RadListView with RadDataPager or DataPager here:
    http://demos.telerik.com/aspnet-ajax/datapager/examples/raddatapagervsdatapager/defaultcs.aspx?product=listview


    Best wishes,
    Vlad
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Chris
    Chris avatar
    63 posts
    Registered:
    05 Jan 2011
    08 Feb 2011
    Link to this post
    Hi Vlad,

    I tried to attach the code but it only allows for images and not zip files.  We're using a custom control so we can maintain the code easier.  I've got KBView.ascx in Resources/Views and below is the code to KBView.cs in the root where I bind the data.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.GenericContent.Model;
    using Telerik.Sitefinity.Localization;
    using Telerik.Sitefinity.Modules.GenericContent.Web.UI;
    using Telerik.Sitefinity.Modules.GenericContent;
     
    using Telerik.Sitefinity.Web.UI.ContentUI;
    using Telerik.Sitefinity.Modules.Pages.Web.UI;
    using Telerik.Sitefinity.News.Model;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.Web.DataResolving;
    using Telerik.Sitefinity.Web.UI;
    using Telerik.Sitefinity.Web.UI.ControlDesign;
    using Telerik.Sitefinity.Web.UI.Fields;
    using Telerik.Sitefinity.Model;
    using Telerik.Web.UI;
     
    namespace KBDisplay
    {
        /// <summary>
        /// A control which displays recent news articles in a rotating manner.
        /// </summary>
        [RequireScriptManager]
        [ControlDesigner(typeof(KBDesigner)), PropertyEditorTitle(typeof(Labels), "Change")]
        public class KBView : SimpleView
        {
            /// <summary>
            /// Default provider name.
            /// </summary>
            private string providerName = "OpenAccessDataProvider";
           
            /// <summary>
            /// Private field for holding the target page with the KBView.
            /// </summary>
            private PageNode targetKBPage;   
     
            /// <summary>
            /// Gets or sets the name of the provider.
            /// </summary>
            /// <value>The name of the provider.</value>
            public virtual string ProviderName
            {
                get
                {
                    return this.providerName;
                }
     
                set
                {
                    this.providerName = value;
                }
            }
     
            /// <summary>
            /// Gets the name of the embedded layout template.
            /// </summary>
            /// <value></value>
            /// <remarks>
            /// Override this property to change the embedded template to be used with the dialog
            /// </remarks>
            protected override string LayoutTemplateName
            {
                get
                {
                  return "KBDisplay.Resources.Views.KBView.ascx";
                }
            }
     
            /// <summary>
            /// Gets the <see cref="T:System.Web.UI.HtmlTextWriterTag"/> value that corresponds to this Web server control. This property is used primarily by control developers.
            /// </summary>
            /// <value></value>
            /// <returns>One of the <see cref="T:System.Web.UI.HtmlTextWriterTag"/> enumeration values.</returns>
            protected override HtmlTextWriterTag TagKey
            {
                get
                {
                    ////Use div wrapper tag to make easier common styling. This will surround the layout template with a div tag.
                    return HtmlTextWriterTag.Div;
                }
            }
     
            /// <summary>
            /// Gets the target news page.
            /// </summary>
            /// <value>The target news page.</value>
            protected PageNode TargetKBPage
            {
                get
                {
                    if (this.targetKBPage == null)
                    {
                        var settings = App.Prepare();
                        settings.TransactionName = "myTransaction";
                        App.Prepare(settings).WorkWith().Page().PageManager.Provider.SuppressSecurityChecks = true;
     
                        this.targetKBPage = App.Prepare(settings).WorkWith().Pages()
                                    .Where(p => p.Page != null &&
                                                p.Page.Controls.Where(c => c.ObjectType.StartsWith(typeof(GenericContentView).FullName)).Count() > 0)
                                    .Get().FirstOrDefault();
                    }
     
                    // it can still be null in case there is no page with a NewsView on it
                    return this.targetKBPage;
                }
            }
     
            /// <summary>
            /// Gets the RadRotator control from the template which is responsible for displaying the news.
            /// </summary>
            /// <value>Instance of a Telerik RadRotator control.</value>
            protected virtual RadListView KBList
            {
                get
                {
                    return this.Container.GetControl<RadListView>("KBList", true);
                }
            }
     
            protected virtual Label lblMessage
            {
                get
                {
                    return this.Container.GetControl<Label>("lblMessage", true);
                }
            }
     
            /// <summary>
            /// Initializes the controls.
            /// </summary>
            /// <param name="controlContainer">The control container.</param>
            protected override void InitializeControls(GenericContainer controlContainer)
            {
                 
               ContentManager manager = ContentManager.GetManager();
               IQueryable<ContentItem> allItems = manager.GetContent()
                                                   .Where(n => n.Status == ContentLifecycleStatus.Live);
     
                List<ContentItem> itemList = new List<ContentItem>(1);
               foreach (ContentItem item in allItems)
               {
                   if (item.TagsText.IndexOf("Knowledgebase") > -1)
                       itemList.Add(item);
               }
     
               this.KBList.DataSource = itemList;
             
     
               this.KBList.PreRender += new EventHandler(KBList_PreRender);
     
                this.KBList.Height = this.Height;
                this.KBList.Width = this.Width;
                        
            }
     
            protected void kbSearchClick(Object sender, EventArgs e)
            {
                this.lblMessage.Text = "Thanks for clicking!";
            
     
            void KBList_PreRender(object sender, EventArgs e)
            {
     
                         
                foreach(var item in this.KBList.Items)
               {
                   
                   if(item.ItemType == RadListViewItemType.DataItem || item.ItemType == RadListViewItemType.AlternatingItem)
                   {
                        
                           var dataItem = item.DataItem as Telerik.Sitefinity.GenericContent.Model.ContentItem;
     
                           
                               //// put sample control in the template only for the test
                                var link = item.FindControl("KBTitle") as HyperLink;
                                var summary = item.FindControl("KBDescription") as Label;
                               //var date = item.FindControl("PublicationDate") as FieldListView;
                               //var viewsCount = item.FindControl("ViewsCount") as TextField;
                                string summaryText = "";
     
     
                                if (dataItem != null)
                                {
                                    if (link != null && this.TargetKBPage != null)
                                    {
                                        link.NavigateUrl = DataResolver.Resolve(dataItem, "URL", null, TargetKBPage.Id.ToString());
                                        link.Text = dataItem.Title;
                                    }
                                    if (summary != null)
                                    {
                                        summaryText = dataItem.Content.ToString();
                                        if (summaryText.Length > 165)
                                        {
                                            summaryText = summaryText.Substring(0, 150) + "...";
                                        }                             
                                        summary.Text = summaryText;
                                    }
                                }
                               /*if (dataItem != null && date != null)
                               {
                                   date.Text = dataItem.PublicationDate.ToString();
                               }
     
                               if (dataItem != null && viewsCount != null)
                               {
                                   viewsCount.Value = dataItem.ViewsCount.ToString();
                               }*/
                             
                   }
               }
           }
        }
    }
  4. Vlad
    Vlad avatar
    498 posts
    Registered:
    15 Jul 2016
    17 Feb 2011
    Link to this post
    Hello Chris,

    We are sorry for the late reply.
    We setup you control, but didn't reproduce the described from you behavior (redirect to default.aspx). Instead, after navigating to the next page the problem was, that the RadListView didn't bind. To fix this problem we moved the Pager control inside the LayoutTemplate of the RadListView:

    <telerik:RadListView ID="KBList" ItemPlaceholderID="ItemsContainer" runat="server"
        EnableEmbeddedSkins="False" EnableEmbeddedBaseStylesheet="False"
        AllowPaging="True">
        <LayoutTemplate>
            <sf:ContentBrowseAndEditToolbar ID="MainBrowseAndEditToolbar" runat="server" Mode="Add"></sf:ContentBrowseAndEditToolbar>
            <asp:PlaceHolder ID="ItemsContainer" runat="server" />
     
            <div id="bottomPagingContent" clientidmode="Static" style="height:35px;" runat="server">
                <div style="float:right;">
                    <asp:DataPager ID="kbBottomPager" PagedControlID="KBList" PageSize="5" runat="server">
                        <Fields>
                            <asp:NextPreviousPagerField FirstPageText="<<" ShowFirstPageButton="True"
                                ShowNextPageButton="False" ShowPreviousPageButton="False" ButtonType="Button" />
                            <asp:NumericPagerField ButtonType="Link" Visible="true" />
                            <asp:NextPreviousPagerField LastPageText=">>" ShowLastPageButton="True"
                                ShowNextPageButton="False" ShowPreviousPageButton="False" ButtonType="Button" />
                        </Fields>
                    </asp:DataPager>
                </div>
            </div>
     
        </LayoutTemplate>
        <ItemTemplate>
            <div id="main_body_listing">
                <div class="listing_title2"><asp:HyperLink ID="KBTitle" runat="server"/></div>
                <asp:Label ID="KBDescription" runat="server" Text="Label"></asp:Label>
            </div>
        </ItemTemplate>
    </telerik:RadListView>

    Can you try this and let us know if you still have any issues.


    Regards,
    Vlad
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. Chris
    Chris avatar
    63 posts
    Registered:
    05 Jan 2011
    17 Feb 2011
    Link to this post
    That was it, had to include the pagers INSIDE the LayoutTemplate and it started working perfectly.  Thanks!
5 posts, 1 answered