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

Forums / Developing with Sitefinity / Filtering Tags and Categories

Filtering Tags and Categories

27 posts, 0 answered
  1. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    17 Aug 2010
    Link to this post
    Ok, here is my dilemna. I am a front end developer and not as familiar with backend custom development solutions, so I have to ask for a little help to accomplish some custom functionality.

    What I am trying to accomplish is this. I want to establish a collection of generic content items representing individual people. Each of these people are to be associated with exactly 1 of 3 possible locations, so I am choosing to use categories for locations. Each of these people are to be associated with any number of a pool of special skills, so I am choosing to use tags for skills. So when I create each person (generic content item), I am able to designate their location (category) and any number of skills associated with that person (tags).

    Then when I create a new page, I use my master page that has a 2 column layout in the body. The left is a wider column that will contain the actual generic content item that I will choose to populate it. The right column is a much narrower 'rail' which has a heading to denote skills. I want to return the list of tags that were associated with that generic content item (person) upon creation. And possibly want to return the category associated with that generic content item (person) as well.

    I tried the tag list and see that it just returns all tags created, so I'm going to need help in accomplishing this programatically.

    Any help is greatly appreciated.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    18 Aug 2010
    Link to this post
    Hi Brett,

    You need to create a custom control that will return only tags and categories associated with a given content item. Here are two articles with samples that shows how to do this

    You could also filter the datasource of CategoriesTree and Tags List controls.

    TagsList - create a custom class that inherits from Telerik.Cms.Engine.WebControls.TagsList and override InitializeControls. There you can access  TagsRepeaterList control and set its datasource. If an content item is selected you have to change the datasource of TagsRepeaterList properly


    CategoriesTree - create a custom class that inherits from Telerik.Cms.Engine.WebControls.Categories.CategoriesTree and override BindCategories method.

    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
  3. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    18 Aug 2010
    Link to this post
    Ivan-

    Your help is greatly appreciated. As I am a front-end developer, my role has always been to create designs, convert those designs to html and css, create master pages, build out pages from the respective master pages and configure out of the box controls. Sometimes I even add custom controls to pages that others have written, but as far as writing the controls myself from scratch....I am learning on the fly, so please forgive my ignorance. I am however eager to learn as my primary tool in the future is going to be Sitefinity. I very much enjoy using it and the functionality it brings, but now it's time for me to learn the hard part....developing custom pieces. I followed the articles you listed below and have created, in my Visual Studio project, an .ascx and .cs file for the control to list the tags related to the generic content item. So now I have an empty .ascx file and my .cs file looks like this...
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
      
    public partial class User_Controls_AttorneyTagList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // create new instance of ContentManager
            Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
            // get all content items
            IList listOfContentItems = contentManager.GetContent();
            if (listOfContentItems.Count > 0)
            {
                // get the third content item
                Telerik.Cms.Engine.IContent thirdContent = contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[2]).ID);
                // get all tags for the given content item
                IList listOfTags = contentManager.GetTags(thirdContent.ID);
                if (listOfTags.Count > 0)
                {
                    foreach (Telerik.Cms.Engine.ITag tagItem in listOfTags)
                        Response.Write(tagItem.TagName + "<br />");
                }
            
        }
    }

    I immediately get 2 errors in Visual Studio.

    Error 55 Using the generic type 'System.Collections.Generic.IList<T>' requires '1' type arguments

    My .ascx file just has the directive stuff at the top....nothing else. Again, please forgive my ignorance, but I am a front end guy trying my best to learn and I'm not sure what my nex move is.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    18 Aug 2010
    Link to this post
    Hi Brett,

    Add using System.Collections instead of using System.Collections.Generic

    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. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    18 Aug 2010
    Link to this post
    Ok, so my next issue is an error upon just adding the control to the page. I get this...

    System.ArgumentOutOfRangeException was unhandled by user code
      Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
      Source="mscorlib"
      ParamName="index"
      StackTrace:
           at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
           at System.ThrowHelper.ThrowArgumentOutOfRangeException()
           at System.Collections.Generic.List`1.get_Item(Int32 index)
           at System.Collections.ObjectModel.Collection`1.System.Collections.IList.get_Item(Int32 index)
           at User_Controls_AttorneyTagList.Page_Load(Object sender, EventArgs e) in c:\Program Files\Telerik\Sitefinity3.7\WebSites\RiggsAbney\User_Controls\AttorneyTagList.ascx.cs:line 19
           at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
           at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
           at System.Web.UI.Control.OnLoad(EventArgs e)
           at System.Web.UI.Control.LoadRecursive()
           at System.Web.UI.Control.AddedControl(Control control, Int32 index)
           at System.Web.UI.ControlCollection.Add(Control child)
           at Telerik.Cms.Web.UI.ControlDesigner.RenderControl()
      InnerException: 


    Thanks for all your help Ivan.
  6. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    18 Aug 2010
    Link to this post
    Ivan-

    After following your lead a little further, I have the control inserted into a page and working properly as it returns only the tags that are associated with that generic content item. They are currently returned via the response.write. Could you give me an example of the syntax to display those returned items in html in the ascx file so that I can arrange and style it?

    Thanks again for everything and for helping a learner.

    Brett
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    18 Aug 2010
    Link to this post
    Hi Brett,

    You can use Repeater control. Inside ItemTemplate or the Repeater control add HyperLink or another control that you want to be rendered. In the code behind you have to bind these repeater - setting DataSource property of the repeater to IList of tags you want to see.

    here is a sample code

    <asp:Repeater runat="server" ID="TagsRepeater">
        <ItemTemplate>
           <asp:HyperLink runat="server"  ID="TagsLink"></asp:HyperLink
         </ItemTemplate>
    </asp:Repeater>



    protected void Page_Load(object sender, EventArgs e)
       {
     
           //just for demonstration we add IList of our tags here
           IList MyTags;
           this.TagsRepeater.DataSource = MyTags;
           this.TagsRepeater.ItemDataBound += new RepeaterItemEventHandler(TagsRepeater_ItemDataBound);
           this.TagsRepeater.DataBind();
       }
     
       void TagsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
       {
           if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
           {
             var link =  e.Item.FindControl("TagsLink") as HyperLink;
             if (link != null)
             {
                 var tag = e.Item.DataItem as ITag;
                 link.Text = tag.TagName;
             }
           }
       }


    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
  8. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    18 Aug 2010
    Link to this post
    Ivan-

    Seems like the home stretch, but unfortunately, I still have a couple problems that I am not sure how to fix.

    ascx file...
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="AttorneyTagList.ascx.cs" Inherits="User_Controls_AttorneyTagList" %>
      
    <asp:Repeater runat="server" ID="TagsRepeater">
        <ItemTemplate>
           <asp:HyperLink runat="server"  ID="TagsLink"></asp:HyperLink>  
         </ItemTemplate>
    </asp:Repeater>
     ascx.cs file...
    using System;
    using System.Collections;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
      
      
    public partial class User_Controls_AttorneyTagList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // create new instance of ContentManager
            Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
            // get all content items
            IList listOfContentItems = contentManager.GetContent();
            if (listOfContentItems.Count > 0)
            {
                // get the third content item
                Telerik.Cms.Engine.IContent thirdContent = contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[2]).ID);
                // get all tags for the given content item
                IList listOfTags = contentManager.GetTags(thirdContent.ID);
                if (listOfTags.Count > 0)
                {
                    // foreach (Telerik.Cms.Engine.ITag tagItem in listOfTags)
                        // Response.Write(tagItem.TagName + "<br />");
                }
            }
            //just for demonstration we add IList of our tags here
            IList MyTags;
            this.TagsRepeater.DataSource = MyTags;
            this.TagsRepeater.ItemDataBound += new RepeaterItemEventHandler(TagsRepeater_ItemDataBound);
            this.TagsRepeater.DataBind();
        }
      
      
        void TagsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var link = e.Item.FindControl("TagsLink") as HyperLink;
                if (link != null)
                {
                    var tag = e.Item.DataItem as ITag;
                    link.Text = tag.TagName;
                }
            }
        }
    }

    I've got 2 errors,

    1) Use of unassigned local variable 'MyTags' line 31 of ascx.cs file.
    2) The type or namespace name 'ITag' culd not be found (are you missing a using directive or an assemble reference?)

    Thanks again for babysitting me Ivan, all your help is truly appreciated.
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    19 Aug 2010
    Link to this post
    Hi Brett,

    1. Set listOfTags as DataSource of the Repeater.

    2. Add reference to Telerik.Cms.Engine

    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. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    19 Aug 2010
    Link to this post
    Ivan-

    Ok, I made those corrections and everything builds and runs fine with no errors. I drag and drop the control onto the page and have styled it, and it does work...meaning it returns specific tags for a content item ID, BUT...it pulls the same tag items for each seperate page that has seperate content items created in them. Also, I can go to the content items module list and edit them and the ID used by the control in each page changes and a different custom tag list is displayed, but again, is displayed in all pages that use the control. In other words, the control is not identifying the ID of the generic content item that is on the page with it and act upon that, it is pulling the ID of the last generic content item that was saved.

    .ascx file
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="AttorneyTagList.ascx.cs" Inherits="User_Controls_AttorneyTagList" %>
      
    <div class="attorneyListContainer">
        <div class="attorneyList">
            <ul>
                <asp:Repeater runat="server" ID="TagsRepeater">
                    <ItemTemplate>
                        <li>
                            <asp:HyperLink runat="server"  ID="TagsLink"></asp:HyperLink>
                        </li>
                    </ItemTemplate>
                </asp:Repeater>
            </ul>
       </div>     
    </div>

    .ascx.cs file
    using System;
    using System.Collections;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
      
      
      
    public partial class User_Controls_AttorneyTagList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // create new instance of ContentManager
            Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
            // get all content items
            IList listOfContentItems = contentManager.GetContent();
            if (listOfContentItems.Count > 0)
            {
                // get the third content item
                Telerik.Cms.Engine.IContent thirdContent = contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[2]).ID);
                // get all tags for the given content item
                IList listOfTags = contentManager.GetTags(thirdContent.ID);
                this.TagsRepeater.DataSource = listOfTags;
                this.TagsRepeater.ItemDataBound += new RepeaterItemEventHandler(TagsRepeater_ItemDataBound);
                this.TagsRepeater.DataBind();
            }
      
        }
      
      
        void TagsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var link = e.Item.FindControl("TagsLink") as HyperLink;
                if (link != null)
                {
                    var tag = e.Item.DataItem as ITag;
                    link.Text = tag.TagName;
                }
            }
        }
    }


    How do I make the control look specifically at the ID of the generic content item on the page with it to determine the custom list of tags to return?

    Thanks very much for all your help.
  11. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    19 Aug 2010
    Link to this post
    Ivan-

    I'm trying to determine the best way to detail my issue to you so that we can figure out a solution as soon as possible. Let me describe the page in general, We have a body area that has 3, or possibly more, sections with generic content controls. 2 of these generic content controls have minimal textual content, and one that has shared content from the generic content module. The custom tag list control we made sits in another placeholder on the page and needs to determine the ID of the generic content from the module, and use only that to determine what tags to were attached to that generic content in the module, and return them to the control.

    Hopefully that helps to clarify.
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    20 Aug 2010
    Link to this post
    Hello Brett,


    You can get the control and its SharedContent property by looking into controls collection of the page

    IList<Telerik.Cms.ICmsWebControl> pageControls = currentPage.Staged.Controls;
     
    foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
    {
     if (webCtrl.ContainerID == "ContentBar" && webCtrl.ControlType == typeof(Telerik.Cms.Engine.WebControls.GenericContent))
     {
        
         Telerik.Cms.Engine.WebControls.GenericContent gcCtrl = webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.GenericContent;
         // this is the IContent object
         var contentItemID = gcCtrl.SharedContent;
     }
    }


    If you are going to use a single shared content item you can use ContentView instead of GenericContent. ContentView has a property SelectedItemId that you can use. The property is located under Obsolete members, but it is working properly.

    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
  13. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    20 Aug 2010
    Link to this post
    Ivan-

    Thank you for your response. I understand the concept of what we are doing, but I'm not sure how to integrate the code you sent into what I currently have as I am not a backend developer. I am looking at the code I have (which I copied into the thread) and the code you just provided and I'm not sure where to put it, or if anything I currently have needs to be replaced with what you gave me.

    Thanks for your help, it seems we are almost to the goal.
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    20 Aug 2010
    Link to this post
    Hello Brett,

    You should put the code in your Tag List control. The code will look for GeneriContent control and its SharedContent property.

    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
  15. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    20 Aug 2010
    Link to this post
    Ivan-

    My question was, do I replace all the prevous code in the control? Does it just replace the IList stuff? When I do that, I get 2 more errors.

    1) The non-generic type 'System.Collections.IList' cannot be used with type arguments
    2) The name 'currentPage' does not exist in the current context
    using System;
    using System.Collections;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
      
      
      
    public partial class User_Controls_AttorneyTagList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // create new instance of ContentManager
            Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
            // get all content items
            IList<Telerik.Cms.ICmsWebControl> pageControls = currentPage.Staged.Controls;
      
            foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
            {
                if (webCtrl.ContainerID == "ContentBar" && webCtrl.ControlType == typeof(Telerik.Cms.Engine.WebControls.GenericContent))
                {
      
                    Telerik.Cms.Engine.WebControls.GenericContent gcCtrl = webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.GenericContent;
                    // this is the IContent object
                    var contentItemID = gcCtrl.SharedContent;
                }
            }
        }
      
      
        void TagsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var link = e.Item.FindControl("TagsLink") as HyperLink;
                if (link != null)
                {
                    var tag = e.Item.DataItem as ITag;
                    link.Text = tag.TagName;
                }
            }
        }
    }
     I really apologize for all the dumb questions, but I am not a backend developer and am doing my best to follow your instructions.

    Thanks,

    Brett
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    22 Aug 2010
    Link to this post
    Hi Brett,

    1. You have to add reference to System.Collection.Generic\

    2. You have to get the current page using one of the code blocks below


    Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;
        // get the CmsPage associated with the current node
    Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;


    or

    CmsManager man = new CmsManager();
    ICmsUrlContext page = (ICmsUrlContext)this.Context.Items[UrlHelper.CmsPageKey];
    string Id = page.PageID.ToString()


    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
  17. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    23 Aug 2010
    Link to this post
    Ok Ivan, I'm getting discouraged. Now that I followed your last post, I now have an error free build, but the control renders nothing.

    using System;
    using System.Collections;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
    using System.Collections.Generic;
      
      
      
    public partial class User_Controls_AttorneyTagList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // create new instance of ContentManager
            Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
            // get all content items
            Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;
            // get the CmsPage associated with the current node
            Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;
            IList<Telerik.Cms.ICmsWebControl> pageControls = currentPage.Staged.Controls;
      
            foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
            {
                if (webCtrl.ContainerID == "ContentBar" && webCtrl.ControlType == typeof(Telerik.Cms.Engine.WebControls.GenericContent))
                {
      
                    Telerik.Cms.Engine.WebControls.GenericContent gcCtrl = webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.GenericContent;
                    // this is the IContent object
                    var contentItemID = gcCtrl.SharedContent;
                }
            }
        }
      
      
        void TagsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var link = e.Item.FindControl("TagsLink") as HyperLink;
                if (link != null)
                {
                    var tag = e.Item.DataItem as ITag;
                    link.Text = tag.TagName;
                }
            }
        }
    }

    Your help is greatly appreciated because I am beginning to fall under a time crunch for this.

    Thanks,

    Brett
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    23 Aug 2010
    Link to this post
    Hello Brett,

    You have to set the DataSource of the repeater and call DataBind method.

    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
  19. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    23 Aug 2010
    Link to this post

    Ivan-

    What is the datasource of the repeater in this scenario? I have included the things you said I needed, but the current source is wrong, but look through the code, and not being a backend developer, I'm not sure what the source should be.

    using System;
    using System.Collections;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
    using System.Collections.Generic;
      
      
      
    public partial class User_Controls_AttorneyTagList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // create new instance of ContentManager
            Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
            // get all content items
            Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;
            // get the CmsPage associated with the current node
            Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;
            IList<Telerik.Cms.ICmsWebControl> pageControls = currentPage.Staged.Controls;
      
            this.TagsRepeater.DataSource = listOfTags;
            this.TagsRepeater.ItemDataBound += new RepeaterItemEventHandler(TagsRepeater_ItemDataBound);
            this.TagsRepeater.DataBind();
      
            foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
            {
                if (webCtrl.ContainerID == "ContentBar" && webCtrl.ControlType == typeof(Telerik.Cms.Engine.WebControls.GenericContent))
                {
      
                    Telerik.Cms.Engine.WebControls.GenericContent gcCtrl = webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.GenericContent;
                    // this is the IContent object
                    var contentItemID = gcCtrl.SharedContent;
                }
            }
        }
      
      
        void TagsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var link = e.Item.FindControl("TagsLink") as HyperLink;
                if (link != null)
                {
                    var tag = e.Item.DataItem as ITag;
                    link.Text = tag.TagName;
                }
            }
        }
    }

    Thanks,

    Brett
  20. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    23 Aug 2010
    Link to this post
    Hi Brett,

    The datasource should be IList of tags. returned for the selected IContent item.
    Here 

    var contentItemID = gcCtrl.SharedContent;


    you get the content item. Then find all tags for this content item using GetTags(Guid contentId) - Get all Tags for a specific content item by passing its ID. This method returns IList that you have to use to bind the control. If the list is empty the content item has not been tagged.

    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
  21. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    23 Aug 2010
    Link to this post
    Ivan-

    Thanks again. I feel like I understand the concept of what we are doing, I just have no idea of the syntax to accomplish it, so I am left after each thread to just muddle my way through trying to accomplish whatever you tell me, or paste any code you give me.

    When I make IList the datasource of the repeater, I get one error...

    'System.Collections.IList' is a 'type' but is used like a 'variable'

    Here is where my code is at this point...\

    using System;
    using System.Collections;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
    using System.Collections.Generic;
      
      
      
    public partial class User_Controls_AttorneyTagList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // create new instance of ContentManager
            Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
            // get all content items
            Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;
            // get the CmsPage associated with the current node
            Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;
            IList<Telerik.Cms.ICmsWebControl> pageControls = currentPage.Staged.Controls;
            this.TagsRepeater.DataSource = IList;
            this.TagsRepeater.ItemDataBound += new RepeaterItemEventHandler(TagsRepeater_ItemDataBound);
            this.TagsRepeater.DataBind();
      
            foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
            {
                if (webCtrl.ContainerID == "ContentBar" && webCtrl.ControlType == typeof(Telerik.Cms.Engine.WebControls.GenericContent))
                {
      
                    Telerik.Cms.Engine.WebControls.GenericContent gcCtrl = webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.GenericContent;
                    // this is the IContent object
                    var contentItemID = gcCtrl.SharedContent;
                }
            }
      
        }
      
      
        void TagsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var link = e.Item.FindControl("TagsLink") as HyperLink;
                if (link != null)
                {
                    var tag = e.Item.DataItem as ITag;
                    link.Text = tag.TagName;
                }
            }
        }
    }

    Thanks very much,

    Brett
  22. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    23 Aug 2010
    Link to this post
    Hello Brett,

    You need to bind the control to list of tags


    protected void Page_Load(object sender, EventArgs e)
    {
     
        var contentManager = new Telerik.Cms.Engine.ContentManager();
        var currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;
     
        IList tagList = null;
        Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;
        IList<Telerik.Cms.ICmsWebControl> pageControls = currentPage.Staged.Controls;
        foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
        {
            if (webCtrl.ContainerID == "ContentBar" && webCtrl.ControlType == typeof(Telerik.Cms.Engine.WebControls.GenericContent))
            {
     
                Telerik.Cms.Engine.WebControls.GenericContent gcCtrl = webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.GenericContent;
                // this is the IContent object
                var contentItem = gcCtrl.SharedContent;
                tagList = contentManager.GetTags(contentItem.ID);
            }
        }
     
        this.TagsRepeater.DataSource = tagList;
        this.TagsRepeater.ItemDataBound += new RepeaterItemEventHandler(TagsRepeater_ItemDataBound);
        this.TagsRepeater.DataBind();
     
    }



    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
  23. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    23 Aug 2010
    Link to this post
    Ivan-

    Thanks so much again. As I look through the code you sent, I do understand WHAT we are doing, I just don't understand what syntax to use in places to execute that plan. I really thought that the last post was going to be the last one when I read your reply, but unfortunately, I got the code in...it buit with no issue, but still renders nothing and I'm not sure why.  I'm going to post my code behind and ascx file one more time in hopes I won't bother you on this thread anymore.

    Thanks!

    ascx file...
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="AttorneyTagList.ascx.cs" Inherits="User_Controls_AttorneyTagList" %>
      
    <div class="attorneyListContainer">
        <div class="attorneyList">
            <ul>
                <asp:Repeater runat="server" ID="TagsRepeater">
                    <ItemTemplate>
                        <li>
                            <asp:HyperLink runat="server"  ID="TagsLink"></asp:HyperLink>
                        </li>
                    </ItemTemplate>
                </asp:Repeater>
            </ul>
       </div>     
    </div>

    and the code behind...
    using System;
    using System.Collections;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
    using System.Collections.Generic;
      
      
      
    public partial class User_Controls_AttorneyTagList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
      
            var contentManager = new Telerik.Cms.Engine.ContentManager();
            var currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;
      
            IList tagList = null;
            Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;
            IList<Telerik.Cms.ICmsWebControl> pageControls = currentPage.Staged.Controls;
      
            foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
            {
                if (webCtrl.ContainerID == "ContentBar" && webCtrl.ControlType == typeof(Telerik.Cms.Engine.WebControls.GenericContent))
                {
      
                    Telerik.Cms.Engine.WebControls.GenericContent gcCtrl = webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.GenericContent;
                    // this is the IContent object
                    var contentItem = gcCtrl.SharedContent;
                    tagList = contentManager.GetTags(contentItem.ID);
                }
            }
            this.TagsRepeater.DataSource = tagList;
            this.TagsRepeater.ItemDataBound += new RepeaterItemEventHandler(TagsRepeater_ItemDataBound);
            this.TagsRepeater.DataBind();
        }
      
      
        void TagsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var link = e.Item.FindControl("TagsLink") as HyperLink;
                if (link != null)
                {
                    var tag = e.Item.DataItem as ITag;
                    link.Text = tag.TagName;
                }
            }
        }
    }

  24. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    24 Aug 2010
    Link to this post
    Is there anything you can see that would cause this to render nothing?  Any and all help is appreciated.
  25. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    25 Aug 2010
    Link to this post
    Ivan-

    Is there any guidance you can offer as to why the code renders nothing in the page. It seems as though this has come so far, with your help, and that it could possibly be wrapped up fairly quickly.

    Your help is greatly appreciated!

    Brett
  26. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Aug 2010
    Link to this post
    Hello Brett,

    webCtrl is not found or the content has not been tagged. As a result the datasource is empty. You can use Visual Studio debugger to check this.

    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. Brett
    Brett avatar
    36 posts
    Registered:
    23 Jul 2010
    25 Aug 2010
    Link to this post
    I am using this control on a page with tagged content as we speak and it returns nothing. S I suppose something is wrong with the logic in webCtrl being found, an as I have noted numerous times, I am not a backend developer and have no clue how to determine what that issue is. I am strictly following your lead at this point.

    Thanks,
    Brett
Register for webinar
27 posts, 0 answered