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

Forums / General Discussions / Getting news categorie and display it in control

Getting news categorie and display it in control

36 posts, 0 answered
  1. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    17 Oct 2010
    Link to this post

    Hello!!!

    I want to get categories in news module and put its categories on page as menu by clicking shows news in selected categories in newsview control below

    Thanks!!!

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Oct 2010
    Link to this post
    Hello rent,

    1. You should get all categories by using GetCategories method of ContentManager class

    Manager.GetCategories(0, 0, "CategoryName ASC");

    2. Then bind your menu to the list of ICategory objects that GetCategroies method returns.

    3. To filter NewsView control you have to append the category name or category ID to the url by using CategoryKey and CategoryKeyType public properties of NewsView control. You can set these properties from the Advanced tab of the control >> QueryString Keys section.

    below is  a sample code that returns categories only of the items you have categorized, so if you have a category which is not used yet, this category will not appear in the menu you want to have.

    var Manager = new ContentManager("News");
    var categories = cntManager.GetCategories(true, false);
    Dictionary<string, List<IContent>> categoryNames = new Dictionary<string, List<IContent>>();
    foreach (ICategory cat in categories )
    {
        if (cat.ContentCount > 0)
        {
      
            
            MetaSearchInfo msi = new MetaSearchInfo(MetaValueTypes.ShortText, "Category", cat.CategoryName, SearchCondition.Equal, JoinType.And);
            var cntInCat = cntManager.GetContent(0, 0, msi);
            categoryNames [cat.CategoryName] = new List<IContent>(cntInCat.Cast<IContent>());
        }
    }
      
      
      
    foreach (KeyValuePair<string, List<IContent>> pair in catNames)
    {
        string filteredCategoryName = pair.Key.ToString();
        int numberOfContentItems = pair.Value.Count;
        
    }


    Best wishes,
    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. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    18 Oct 2010
    Link to this post
    Thank you very much Ivan!!!
    And I've detalized my problems (see attached JPEG image - example of another web site).
    I want StePanelBar to show one level sitye menu. And by clicking for example on News(Новости) shows categories in control such as on picture, and by clicking categories swowing news from this category in newsview ontrol.
    Thanks.

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Oct 2010
    Link to this post
    Hello rent,

    My code shows hot do get the categories. The only thing that you have to do is binding them to an ASP.NET Repeater control which has a HyperLink inside the ItemTemplate.

    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. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    22 Oct 2010
    Link to this post
    How to configue SitePanrlBar to show only first root items a site menu? E.g. News without child nodes and etc
    Thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    22 Oct 2010
    Link to this post
    Hi rent,

    News are IContent items and they could not have child nodes. The IContent object created through News Manager does not have a parent.

    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
  7. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    22 Oct 2010
    Link to this post
    Sorry, I told about site menu in SitePanelBar
    Thanks
  8. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    25 Oct 2010
    Link to this post
    How to configure Site PanelBar control in sitefinity to show only root items in site menu?
    Thanks
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Oct 2010
    Link to this post
    Hi rent,

    You can set MaxDataBindDepth property of the control to 1. This property gets or sets the maximum number of levels to bind to the RadPanelBar  control. The default is -1, which binds all the levels in the data source to the control.

    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
  10. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    25 Oct 2010
    Link to this post
    thank you very much Ivan!!!
  11. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    27 Oct 2010
    Link to this post
    Hello!!!
    Why my Site PanelBat is not aligned wtih parent div? Which CSS code I must wrote?
    Thanks
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 Oct 2010
    Link to this post
    Hi rent,

    The SitePanelBar is aligned based on the css rules you have for the ContentPlaceHolder inside the control has been dropped. If you want to style the control itself you should use CSS Skin File Selectors

    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
  13. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    27 Oct 2010
    Link to this post
    ContentPlaceHolder does not have CSS? but CSS have a left div which is parent for left ContentPlaceHolder 
    I must wrote a CSS for ContentPlaceHolder ?
  14. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    28 Oct 2010
    Link to this post
    I'm steel wait for answer....
  15. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    10 Nov 2010
    Link to this post
    Hello!!!
    I'm create user control NewsCategories.ascx with following:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsCategories.ascx.cs" Inherits="Sitefinity_UserControls_Nchtec_NewsCategories" %>
     
    <asp:Repeater ID="NewsCategoriesRepeater" runat="server">
    </asp:Repeater>

    And code file NewsCategories.ascx.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
    using System.Collections;
     
    public partial class Sitefinity_UserControls_Nchtec_NewsCategories : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var Manager = new ContentManager("News");
                var categories = Manager.GetCategories(true, false);
                IList<NewsCategories> CatList = new List<NewsCategories>();
                foreach (ICategory cat in categories)
                {
                    if (cat.ContentCount > 0)
                    {
                        NewsCategories category = new NewsCategories();
                        category.ID = cat.ID;
                        category.Name = cat.CategoryName;
                        CatList.Add(category);
                    }
                }
                NewsCategoriesRepeater.DataSource = CatList;
                NewsCategoriesRepeater.DataMember = "Name";
            }
        }
        internal class NewsCategories
        {
            internal Guid ID { get; set; }
            internal string Name { get; set;}
        }
    }

    But categories dos not show. Where I mistake?
    And how to do such on this picture ??? How to display news categories and show news of selected categories such in example? I try use ASP.NET Repeater? but while unseccessfull.
    Thanks
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Nov 2010
    Link to this post
    Hi rent,

    You are not calling DataBind method of the repeater control.

    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
  17. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    10 Nov 2010
    Link to this post
    Thanks Ivan! I missed DataBind method of repeater control. But I have another question:
    Hot to do this such on picture? I want when news categories selected to show news in this category in NewsView control.
    Thanks.
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Nov 2010
    Link to this post
    Hello rent,

    You should have ItemTemplate in your Repater control. You have to subscribe for ItemDataBound event and set the values of the controls in your template. You can use GetContent(params IMetaSearchInfo[] filter) - to get a filtered list of news items based on a category.

    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
  19. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    10 Nov 2010
    Link to this post
    Thanks Ivan!!!
    But I want use my new control with sitefinity News View control. In my NewsCategories.ascx user control I want to put news view control and showing in this selected category news. Any ideas?
    Thanks.

  20. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Nov 2010
    Link to this post
    Hi rent,

    You can configure NewsView control as explained in this post. When you add the control declaratively in your template you can use its public properties.

    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
  21. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    10 Nov 2010
    Link to this post
    But I want to use selected news category Id in my control to use in news view control to show news in selected category. How to simple made this?
    Thanks.
  22. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    11 Nov 2010
    Link to this post
    Hello!!!
    I'm still waiting for a sulution. 
    I want when click on categories in user control in news view control showing news. How to made this without filters using by GetContent - simple in news view control change CategoryID property?
    Thanks.
  23. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    11 Nov 2010
    Link to this post
    There is my C# code and User Control markup:
    NewsCategories.ascx:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsCategories.ascx.cs" Inherits="Sitefinity_UserControls_Nchtec_NewsCategories" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register assembly="Telerik.News" namespace="Telerik.News.WebControls" tagprefix="cc1" %>
     
    <asp:Repeater ID="NewsCategoriesRepeater" runat="server">
            <ItemTemplate>
                    <asp:HyperLink
                    Text='<%# DataBinder.Eval(Container.DataItem,"Name")%>'
                    NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"ID")%>'
                    runat="server" ID="Hyperlink1">
                    </asp:HyperLink >
            </ItemTemplate>
            <SeparatorTemplate>|</SeparatorTemplate>
    </asp:Repeater>
    <cc1:NewsView ID="NewsView1" runat="server">
    </cc1:NewsView>

    NewsCategories.ascx.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
    using System.Collections;
     
    public partial class Sitefinity_UserControls_Nchtec_NewsCategories : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var Manager = new ContentManager("News");
                var categories = Manager.GetCategories(true, false);
                IList<NewsCategories> CatList = new List<NewsCategories>();
                foreach (ICategory cat in categories)
                {
                    if (cat.ContentCount > 0)
                    {
                        NewsCategories category = new NewsCategories();
                        category.ID = cat.ID;
                        category.Name = cat.CategoryName;
                        CatList.Add(category);
                    }
                }
                NewsCategoriesRepeater.DataSource = CatList;
                NewsCategoriesRepeater.DataBind();
            }
        }
        internal class NewsCategories
        {
            public Guid ID { get; set; }
            public string Name { get; set;}
        }
    }

    I put thisd user control to simple sitefinity page named news (news.aspx). I want when users clicked on Hyperlink in repeater control  in NewsView1 setting CategoryID property. I think UI need correct NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"ID")%>' add news.aspx?CatID=CategoryID. How to made correct?
    Thanks.
  24. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Nov 2010
    Link to this post
    Hi rent,

    By default the NewCategoryKey is "NewsCatID". You can check QueryString Keys properties section of NewsView control. For CategoryKeyType you can use Name or ID of the category. When you click a link from your control you need to pass the ID of the category or its name to NewsCatID querystring key. Then the NewsView will be filtered internally.

    Best wishes,
    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
  25. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    11 Nov 2010
    Link to this post
    Thank you Ivan!!!
    I make NavigateURL property like this:
    NavigateUrl='<%# "~/news.aspx?NewsCatID=" + DataBinder.Eval(Container.DataItem,"ID")%>'

    1. But NewsView  control does not filtered internally. What is wrong? 
    2. For NewsView templates in NewsCategories.ascx.cs I made following:
    [WebEditor("Telerik.FileManager.UrlWebEditor, Telerik.FileManager"), Themeable(false), DefaultValue("")]
        [Category("Appearance")]
        [Browsable(true)]
        public string SingleItemTemplatePath
        {
            get { return this.NewsView1.SingleItemTemplatePath;}
            set {this.NewsView1.SingleItemTemplatePath = value;}
        }
        [WebEditor("Telerik.FileManager.UrlWebEditor, Telerik.FileManager"), Themeable(false), DefaultValue("")]
        [Category("Appearance")]
        [Browsable(true)]
        public string ItemListTemplatePath
        {
            get { return this.NewsView1.ItemListTemplatePath; }
            set { this.NewsView1.ItemListTemplatePath = value; }
        }

    I made this because I want delete "Go back" link in News View control. And I downloaded Sitefinity_3_7_standard_trial_NET40_ExternalTemplates.zip and use \Sitefinity\ControlTemplates\News\ListPageDetails.ascx and \Sitefinity\ControlTemplates\News\ListPageMaster.ascx for this. It is right?
  26. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Nov 2010
    Link to this post
    Hello rent,

    1. Could you show the link structure after you click on the link
    2. ListPageMaster.ascx and ListPageDetails.ascx are the templates you have to use.

    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
  27. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    11 Nov 2010
    Link to this post
    Thanks Ivan!!!
    1. I has a little mistake in my previos question. When I open news page http://localhost/NCHTEC/news.aspx in NewsView control shows all news, because I don't know how to append page queystring from first hyperlink link. But after categories select url became http://localhost/NCHTEC/news.aspx?NewsCatID=d89ca3ab-aad7-4528-96a3-4cb7d0c96483 and in NewsView shows news from this category....
    I must to add to page url when open news.aspx a query string NewsCatID with first category ID. How to do this?
    2. And why when selectt news in NewsView control getting an error HTTP 404?? in news category http://localhost/NCHTEC/news.aspx?NewsCatID=b8ce8a34-a4d1-427c-be1a-d335f580b162 one news Url is like http://localhost/nchtec/news/10-10-14/%d0%91%d1%80%d0%b5%d0%b9%d0%bd-%d1%80%d0%b8%d0%bd%d0%b3.aspx
    Thanks.
  28. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Nov 2010
    Link to this post
    Hi rent,

    1. To set the NavigateUrl of the Link you can use  string format or in the Eval expression or subscribe for ItemDataBound event of the repeater and set the value in the code behind.

    2. You get an error, because you are using some special chars or not Latin chars in the tile of your news item.

    Just to let you know the response time in forums is 72 hours. You can use support subscription with 24/48 hrs guarantee response time.

    Greetings,
    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
  29. rent
    rent avatar
    104 posts
    Registered:
    05 May 2008
    12 Nov 2010
    Link to this post

    Thank you Ivan!!!

    And one question again:

    In this situation (this solution) for news and events when user view news or events detail in top of news view or events view control show all news link. This link return to all news list but I want to return only back. How to do this?

    Thanks

  30. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Nov 2010
    Link to this post
    Hello rent,

    To return back on the previous page you can use javascript

    <a href="javascript: history.go(-1)">Back</a>

    You can modify ListPageDetail.ascx of EventsView or NewsView controls and change the back button.

    Best wishes,
    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
Register for webinar
36 posts, 0 answered
1 2