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

Forums / General Discussions / Is there a paging mechanism in the forum control?

Is there a paging mechanism in the forum control?

9 posts, 0 answered
  1. Robert
    Robert avatar
    10 posts
    Registered:
    29 Oct 2010
    02 Nov 2010
    Link to this post
    Hello everyone, is there a paging mechanism in the forum control? i have plenty of threads  and  i  want to divide the threads into several pages, then  how can i make it?

    Thanks
    Robert 
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Nov 2010
    Link to this post
    Hello Robert,

    To enable paging for threads you have to modify Sitefinity\ControlTemplates\Forums\SingleForum.ascx and the GridView declaration in it

    <asp:GridView ID="allThreads" runat="server" AutoGenerateColumns="false" CssClass="sf_forumsThreadsList" GridLines="none"  AllowPaging="true" PageSize="5">
     
    .....
        ....

    You can do the same for ForumList - when all forums are listed.

    All the best,
    Ivan Dimitrov
    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. Robert
    Robert avatar
    10 posts
    Registered:
    29 Oct 2010
    02 Nov 2010
    Link to this post
    Hi  Ivan,thanks for your reply and sincere help. I modified the file as you said and the paging effect actually  appeared on my website. However, once i clicked on the serial number, an error occurred

    GridView“allThreads” aroused unsettled incident “PageIndexChanging”


    then what should I do?

    Thanks
    Robert


  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Nov 2010
    Link to this post
    Hello Robert,

    The problem is that we are not using SqlDataSource or ObjectDataSource to bind the control.
    You could hide the default GridView control by setting its Visible property. Then you need to add a new GridView ( the same as the default one, you can just copy paste it, but you should give a new ID of the control - say GridView1). Then you should bind the control through ObjectDataSource  control as shown below


    template

    <asp:GridView OnPageIndexChanging="PageIndexChanging" ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="sf_forumsThreadsList" GridLines="none"  AllowPaging="true" PageSize="2">
            <Columns>
                <asp:TemplateField HeaderText="<%$Resources:Status %>">
                    <ItemTemplate>
                        <asp:Literal ID="threadStatus" runat="server"></asp:Literal>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:ButtonField DataTextField="Title" ButtonType="link" CommandName="OpenThread" HeaderText="<%$Resources:Thread %>" SortExpression="Title"><ItemStyle CssClass="sf_forumThreadTitle" /></asp:ButtonField>
                <asp:TemplateField HeaderText="<%$Resources:Created %>">
                    <ItemTemplate>
                        <sfWeb:DateTimeLiteral ID="dateCreated" runat="server" DateFormatString="dd MMM yyyy, hh:mm"></sfWeb:DateTimeLiteral>
                    </ItemTemplate>
                    <ItemStyle CssClass="sf_forumDate" />
                </asp:TemplateField>
                <asp:BoundField DataField="ChildPostsCount" HeaderText="<%$Resources:Posts %>" />
                <asp:TemplateField HeaderText="<%$Resources:LastPost %>" HeaderStyle-CssClass="sf_forumAuthor">
                    <ItemStyle CssClass="sf_forumAuthor" />
                    <ItemTemplate>
                        <asp:LinkButton ID="goToPost" runat="server"><sfWeb:DateTimeLiteral ID="lastPostDate" runat="server" DateFormatString="dd MMM yyyy, hh:mm"></sfWeb:DateTimeLiteral></asp:LinkButton>
                        By 
                        <prof:ManageProfile ID="lastPostAuthor" ShowAnonymousLabel="true" AnonymousLabel="<%$ Resources:Anonymous %>" runat="server">
                            <ViewTemplate>
                                <asp:Label ID="FirstName" runat="Server"></asp:Label
                                <asp:Label ID="LastName" runat="Server"></asp:Label>
                            </ViewTemplate>
                        </prof:ManageProfile>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>


    cs

    protected override void OnLoad(EventArgs e)
       {
           base.OnLoad(e);
           BindForumsGrid();
           GridView1.DataBind();
       }
     
       void BindForumsGrid()
       {
           // here you have to pass the ID of the forum to get the threads.
           // you can use a parameter of BindForumsGrid.
           // you could get the form id form the query string if
           // SingleForumPage property of Forums control.
           ObjectDataSource dataSource = new ObjectDataSource();
           dataSource.ID = "ForumsDataSource";
           dataSource.TypeName = "Telerik.Forums.ForumManager";
           dataSource.SelectMethod = "GetForumThreads";
           dataSource.SelectParameters.Add("parentForumID", "A3A77927-DD22-4A1A-B202-311703435E5F");
           dataSource.SelectParameters.Add("excludeHidden", "false");
          
            
           this.Controls.Add(dataSource);
           GridView1.DataSource = dataSource;
       }
     
     
       protected void PageIndexChanging(object sender, GridViewPageEventArgs e)
       {
           var g = sender as GridView;
           BindForumsGrid();
           g.PageIndex = e.NewPageIndex;
           g.DataBind();
       }


    Sincerely yours,
    Ivan Dimitrov
    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
  5. Robert
    Robert avatar
    10 posts
    Registered:
    29 Oct 2010
    02 Nov 2010
    Link to this post
    Hello Ivan,thanks for your reply.  First, I'm not sure how to use the cs code you offered, so can you please give guidance in more details? Secondly, after i copied  and paste the template you offered in SingeForum.ascx and clicked the forum title, another error occurred:
    System.Web F:\website\CA9465DB\Sitefinity\ControlTemplates\Forums\SingleForum.ascx(49): error BC30456: “PageIndexChanging”is not the member of “ASP.sitefinity_controltemplates_forums_singleforum_ascx”。

    Thanks
    Robert


  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Nov 2010
    Link to this post
    Hi Robert,

    You have to create a code behind of the template or write the code inline. I am not able to replicate the error you are getting.

    All the best,
    Ivan Dimitrov
    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
  7. Robert
    Robert avatar
    10 posts
    Registered:
    29 Oct 2010
    04 Nov 2010
    Link to this post
    Hi Ivan,thanks for your reply again.Now i want to show your several files.I think there must be some errors i couldn't find out.

    SingleForum.ascx
    <%@ Register Assembly="Telerik.Security" Namespace="Telerik.Security.WebControls" TagPrefix="prof" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %>
     
    <sfWeb:CssFileLink ID="CssFileLink1" FileName="~/Sitefinity/ControlTemplates/Forums/forumsCommonLayout.css" Media="screen" runat="server" />
    <div class="sf_forumsWrapper">
        <h2 class="sf_forumTitle"><asp:Literal ID="forumTitle" runat="server"></asp:Literal></h2>
        <p class="sf_back"><asp:LinkButton ID="backToForumsButton1" runat="server" Text="<%$Resources:BackToAllForums %>"></asp:LinkButton></p>
        <p class="sf_createNewItem"><asp:LinkButton id="newThreadButton1" runat="server" Text="<%$Resources:NewThread %>"></asp:LinkButton></p>
        <asp:Label ID="emptyMessage" runat="server" Text="<%$Resources:NoThreads %>"></asp:Label>
         
    <asp:GridView Visible="false" ID="allThreads" runat="server" AutoGenerateColumns="false" CssClass="sf_forumsThreadsList" GridLines="none" AllowPaging="true" PageSize="11">
            <Columns>
                <asp:TemplateField HeaderText="<%$Resources:Status %>">
                    <ItemTemplate>
                        <asp:Literal ID="threadStatus" runat="server"></asp:Literal>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:ButtonField DataTextField="Title" ButtonType="link" CommandName="OpenThread" HeaderText="<%$Resources:Thread %>" SortExpression="Title"><ItemStyle CssClass="sf_forumThreadTitle" /></asp:ButtonField>
                <asp:TemplateField HeaderText="<%$Resources:Created %>">
                    <ItemTemplate>
                        <sfWeb:DateTimeLiteral ID="dateCreated" runat="server" DateFormatString="dd MMM yyyy, hh:mm"></sfWeb:DateTimeLiteral>
                    </ItemTemplate>
                    <ItemStyle CssClass="sf_forumDate" />
                </asp:TemplateField>
                <asp:BoundField DataField="ChildPostsCount" HeaderText="<%$Resources:Posts %>" />
                <asp:TemplateField HeaderText="<%$Resources:LastPost %>" HeaderStyle-CssClass="sf_forumAuthor">
                    <ItemStyle CssClass="sf_forumAuthor" />
                    <ItemTemplate>
                        <asp:LinkButton ID="goToPost" runat="server"><sfWeb:DateTimeLiteral ID="lastPostDate" runat="server" DateFormatString="dd MMM yyyy, hh:mm"></sfWeb:DateTimeLiteral></asp:LinkButton>
                        By 
                        <prof:ManageProfile ID="lastPostAuthor" ShowAnonymousLabel="true" AnonymousLabel="<%$ Resources:Anonymous %>" runat="server">
                            <ViewTemplate>
                                <asp:Label ID="FirstName" runat="Server"></asp:Label
                                <asp:Label ID="LastName" runat="Server"></asp:Label>
                            </ViewTemplate>
                        </prof:ManageProfile>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
     
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="sf_forumsThreadsList" GridLines="none" AllowPaging="true" PageSize="11">
            <Columns>
                <asp:TemplateField HeaderText="<%$Resources:Status %>">
                    <ItemTemplate>
                        <asp:Literal ID="threadStatus" runat="server"></asp:Literal>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:ButtonField DataTextField="Title" ButtonType="link" CommandName="OpenThread" HeaderText="<%$Resources:Thread %>" SortExpression="Title"><ItemStyle CssClass="sf_forumThreadTitle" /></asp:ButtonField>
                <asp:TemplateField HeaderText="<%$Resources:Created %>">
                    <ItemTemplate>
                        <sfWeb:DateTimeLiteral ID="dateCreated" runat="server" DateFormatString="dd MMM yyyy, hh:mm"></sfWeb:DateTimeLiteral>
                    </ItemTemplate>
                    <ItemStyle CssClass="sf_forumDate" />
                </asp:TemplateField>
                <asp:BoundField DataField="ChildPostsCount" HeaderText="<%$Resources:Posts %>" />
                <asp:TemplateField HeaderText="<%$Resources:LastPost %>" HeaderStyle-CssClass="sf_forumAuthor">
                    <ItemStyle CssClass="sf_forumAuthor" />
                    <ItemTemplate>
                        <asp:LinkButton ID="goToPost" runat="server"><sfWeb:DateTimeLiteral ID="lastPostDate" runat="server" DateFormatString="dd MMM yyyy, hh:mm"></sfWeb:DateTimeLiteral></asp:LinkButton>
                        By 
                        <prof:ManageProfile ID="lastPostAuthor" ShowAnonymousLabel="true" AnonymousLabel="<%$ Resources:Anonymous %>" runat="server">
                            <ViewTemplate>
                                <asp:Label ID="FirstName" runat="Server"></asp:Label
                                <asp:Label ID="LastName" runat="Server"></asp:Label>
                            </ViewTemplate>
                        </prof:ManageProfile>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
     
        <p class="sf_createNewItem"><asp:LinkButton id="newThreadButton2" runat="server" Text="<%$Resources:NewThread %>"></asp:LinkButton></p>
        <p class="sf_back"><asp:LinkButton ID="backToForumsButton2" runat="server" Text="<%$Resources:BackToAllForums %>"></asp:LinkButton></p>
    </div>


    forum.master.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    public partial class MasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
     
    protected override void OnLoad(EventArgs e)
       {
           base.OnLoad(e);
           BindForumsGrid();
           GridView1.DataBind();
       }
     
    void BindForumsGrid()
       {
           // here you have to pass the ID of the forum to get the threads.
           // you can use a parameter of BindForumsGrid.
           // you could get the form id form the query string if
           // SingleForumPage property of Forums control.
           ObjectDataSource dataSource = new ObjectDataSource();
           dataSource.ID = "ForumsDataSource";
           dataSource.TypeName = "Telerik.Forums.ForumManager";
           dataSource.SelectMethod = "GetForumThreads";
           dataSource.SelectParameters.Add("forum", "A3A77927-DD22-4A1A-B202-311703435E5F");
           dataSource.SelectParameters.Add("excludeHidden", "false");
           
             
           this.Controls.Add(dataSource);
           GridView1.DataSource = dataSource;
       }
      
       protected void PageIndexChanging(object sender, GridViewPageEventArgs e)
       {
           var g = sender as GridView;
           BindForumsGrid();
           g.PageIndex = e.NewPageIndex;
           g.DataBind();
       }
    }

    forum.master
    <%@ Master Language="C#" CodeFile="forum.master.cs" Inherits="MasterPage" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
       <title>my_site</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="forum.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server"><asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
    <div class="main">
     <div class="content">
    <asp:ContentPlaceHolder id="forum" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </div>

    </form>
    </body>
    </html>

    When I  click the forum page, the error occurred
     " CS0103: the current context does not exist  the name "GridView1"  "

    Thanks 
    Robert   
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Nov 2010
    Link to this post
    Hello Robert,

    You should access the GridView1 from SingleForum.ascx.cs - the code behind of SingleForum.ascx

    Kind regards,
    Ivan Dimitrov
    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
  9. Robert
    Robert avatar
    10 posts
    Registered:
    29 Oct 2010
    12 Nov 2010
    Link to this post
    Hello Ivan, thanks a lot for your help.  The problem has been solved. Wonderful services!
    Thanks again.

    Robert
Register for webinar
9 posts, 0 answered