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

Forums / Developing with Sitefinity / Sorting forums category

Sorting forums category

7 posts, 0 answered
  1. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    10 May 2010
    Link to this post
    Hellou,
    I have problem to sort forums by category alphabetically.

    Look at code:

    protected void Page_Load(object sender, EventArgs e)
     {
        foreach (RepeaterItem item in forumsRepeater.Items){
             
                 Label chb = (Label)item.FindControl("Literal1");
                 Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager();
     
                 //// get all categories sorted by an expression
                 IList listOfAllCategories = forumManager.GetCategories("Name ASC");
                 if (listOfAllCategories.Count > 0)
                 {
                     foreach (Telerik.Forums.ICategory categ in listOfAllCategories)
                     {
                         chb.Text = categ.Name;
                     }
              }
             
         }
     }

    Any help how to resolve this problem,
    thanks.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 May 2010
    Link to this post
    Hi Milos Tadic,

    I am not able to reproduce a problem with etCategories(string sortExpr) method. You could take a look at the attached video.

    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.
  3. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    10 May 2010
    Link to this post
    Thanks Ivan, but this video didn't help me.

    How to pass value categ.Name to Labels id?
    Or how to change this

     <h1 class="sf_forumCategoryTitle"> <%#DataBinder.Eval(Container.DataItem, "Name")%></h1>

    to use my sort category name?

    Here is my forumslist.ascx control code:

    <%@ Control Language="C#" AutoEventWireup="true" %>
    <%@ 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" />
      
     <script type="text/C#" runat="server" >
          
         protected void Page_Load(object sender, EventArgs e)
        {
           foreach (RepeaterItem item in forumsRepeater.Items){
                
                    Label chb = (Label)item.FindControl("Literal1");
                    Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager();
     
                    //// get all categories sorted by an expression
                    IList listOfAllCategories = forumManager.GetCategories("Name ASC");
                    if (listOfAllCategories.Count > 0)
                    {
                        foreach (Telerik.Forums.ICategory categ in listOfAllCategories)
                        {
                            chb.Text = categ.Name;
                        }
                 }
                
            }
        }
         
      </script>
    <div class="sf_forumsWrapper">
    <asp:Repeater ID="forumsRepeater" runat="server" >
        <HeaderTemplate>
             
        </HeaderTemplate>
        <ItemTemplate>
     
                <h1 class="sf_forumCategoryTitle"><asp:Label id="Literal1" runat="server" /></h1>
     
            <asp:GridView ID="inner" runat="server" CssClass="sf_forumsList" AutoGenerateColumns="false" GridLines="none">
                <Columns>
                    <asp:TemplateField Visible="false" HeaderText="<%$Resources:Status %>">
                        <ItemTemplate>
                            <asp:Literal ID="forumStatus" runat="server"></asp:Literal>
                        </ItemTemplate>
                    </asp:TemplateField>
                  <%--  <asp:ImageField DataImageUrlField="http://localhost//images/arrow.gif" />--%>
                    <asp:TemplateField HeaderText="<%$Resources:Forum %>">
                        <ItemTemplate>
                            <asp:LinkButton ID="btnOpenForum" runat="server"></asp:LinkButton>
                            <div><asp:Literal id="lblDescription" runat="server"></asp:Literal></div>
                        </ItemTemplate>
                        <ItemStyle CssClass="sf_forumTitle" />
                    </asp:TemplateField>
                     
                    <asp:BoundField DataField="PostsCount" HeaderText="Post" />
                    <asp:BoundField DataField="ThreadsCount" HeaderText="Tema" />
                    <asp:TemplateField HeaderText="Zadnji Odgovor" HeaderStyle-CssClass="sf_forumAuthor">
                        <ItemTemplate>
                            <asp:LinkButton ID="goToPost" runat="server" CausesValidation="false"><sfWeb:DateTimeLiteral ID="lastPostDate" runat="server" DateFormatString="dd MMM yyyy, hh:mm"></sfWeb:DateTimeLiteral></asp:LinkButton>
                            <asp:Label ID="noPosts" runat="server" Text="Nema Odgovora"></asp:Label>
           
                            <asp:Label ID="byText" runat="server" Text="By "></asp:Label>
                            <prof:ManageProfile ID="lastPostAuthor" runat="server" ShowAnonymousLabel="true" AnonymousLabel="<%$ Resources:Anonymous %>">
                                <ViewTemplate>
                                    <asp:Literal ID="FirstName" runat="Server"></asp:Literal
                                    <asp:Literal ID="LastName" runat="Server"></asp:Literal>
                                </ViewTemplate>
                            </prof:ManageProfile>
                        </ItemTemplate>
                        <ItemStyle CssClass="sf_forumAuthor" />
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </ItemTemplate>
        <FooterTemplate>
             
        </FooterTemplate>
    </asp:Repeater>
     
            <h2 class="sf_forumCategoryTitle"><asp:Literal ID="UncategorizedHeader" runat="server" Text="<%$Resources:Uncategorized %>"></asp:Literal></h2>
     
        <asp:GridView ID="Uncategorized" runat="server" CssClass="sf_forumsList" AutoGenerateColumns="false" GridLines="none">
            <Columns>
                <asp:TemplateField HeaderText="<%$Resources:Status %>">
                    <ItemTemplate>
                        <asp:Literal ID="forumStatus" runat="server"></asp:Literal>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="<%$Resources:Forum %>">
                    <ItemTemplate>
                        <asp:LinkButton ID="btnOpenForum" runat="server"></asp:LinkButton>
                        <div><asp:Label ID="lblDescription" runat="server"></asp:Label></div>
                    </ItemTemplate>
                    <ItemStyle CssClass="sf_forumTitle" />
                </asp:TemplateField>
                 
                <asp:BoundField DataField="PostsCount" HeaderText="<%$Resources:Posts %>" />
                <asp:BoundField DataField="ThreadsCount" HeaderText="<%$Resources:Threads %>" />
                <asp:TemplateField HeaderText="<%$Resources:LastPost %>" HeaderStyle-CssClass="sf_forumAuthor">
                    <ItemStyle CssClass="sf_forumAuthor" />
                    <ItemTemplate>
                        <asp:LinkButton ID="goToPost" runat="server" CausesValidation="false"><sfWeb:DateTimeLiteral ID="lastPostDate" runat="server" DateFormatString="dd MMM yyyy, hh:mm"></sfWeb:DateTimeLiteral></asp:LinkButton>
                        <asp:Label ID="noPosts" runat="server" Text="<%$Resources:NoPosts %>"></asp:Label>
                      
                        <asp:Label ID="byText" runat="server" Text="By "></asp:Label>
                        <prof:ManageProfile ID="lastPostAuthor" ShowAnonymousLabel="true" AnonymousLabel="<%$ Resources:Anonymous %>" runat="server">
                            <ViewTemplate>
                                <asp:Literal ID="FirstName" runat="Server"></asp:Literal
                                <asp:Literal ID="LastName" runat="Server"></asp:Literal>
                            </ViewTemplate>
                        </prof:ManageProfile>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 May 2010
    Link to this post
    Hello Milos Tadic,

    The code you use is wrong and if you attach it to VS debugger you will see that forumsRepeater.Items is null and your code does not executed.

    You should subscribe for ItemDataBound  event of the repeater and access the ItemTemplate and your control.

    protected void Page_Load(object sender, EventArgs e)
       {
     
           forumsRepeater.ItemDataBound += new RepeaterItemEventHandler(forumsRepeater_ItemDataBound);
         
      }
     
       void forumsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
       {
           if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
           {
               Label chb = (Label)e.Item.FindControl("Literal1");
     
                     ....
            }
        }

    Note that the code will not filter the forums it gets only the categories as a string with no relation to the forums.

    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.
  5. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    10 May 2010
    Link to this post
    Yes, you are right, I try ItemDataBound before and I got just a string without relation.
    Is there solution to establish relation with forums?
    Thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 May 2010
    Link to this post
    Hi Milos Tadic,

    There is not method in the API that you can use to sort forums by category.  You could create a custom RadGrid control wrapped in the repeater of ForumLists and make the sorting externally in a given order

    You could use

    •  GetForums(ICategory category, bool excludeHidden)
    •  GetForums(Guid categoryID, bool excludeHidden)
    To get the forums in a list and then bind the RadGrid to this list in an ordered way.    

    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.
  7. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    10 May 2010
    Link to this post
    Well, that is more difficult than I thought

    I found this:
    http://www.sitefinity.com/support/code-library/sitefnity/userandcustomcontrols/getting-forums-by-category-control-based-on-sitefinitys-template.aspx

    but my server use .NET 2.0 and this control use Linq

    Thanks anyway.
    If others have some solution or proposal, that would be very nice.

    Best regards,
    Milos Tadic.
Register for webinar
7 posts, 0 answered