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

Forums / Developing with Sitefinity / Get All Generic Content

Get All Generic Content

3 posts, 0 answered
  1. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    29 Jun 2010
    Link to this post
    Hey -
    I need to select the generic content inside my custom generic content view. I need to use the button selector for the same. Please help me in my task.
    How do I place the button selector as a property in the property window of my control.

    regards,
    Siddesh Kapadi
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    29 Jun 2010
    Link to this post
    Hi Siddesh Kapadi,

    Here is a blog post that explains how to create a custom WebUITypeEditor  Custom WebUITypeEditor. if you want to use it with the built-in ContentView control, you have to create a custom class that inherits from it and implement a public property that will use the selector.

    public class ContentViewCustomControl : ContentView
    {
        public ContentViewCustomControl()
        {
      
        }
      
        public override Type LocalizationAssemblyInfo
        {
            get
            {
                return GetType();
            }
            set
            {
                base.LocalizationAssemblyInfo = value;
            }
        }
      
         
      
        public override System.Type AssemblyInfo
        {
            get
            {
                return GetType();
            }
            set
            {
                base.AssemblyInfo = value;
            }
        }
      
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/Generic_Content/ContentViewItemList.ascx";
            }
       
        }
      
        //public override string SingleItemTemplatePath
        //{
        //    get
        //    {
        //        return "path to single item template path";
        //    }
      
        //}
     
     // add property and selector
     [WebEditor("CustomWebEditor, App_Code")]
        public Guid ContentID
        {
            get
            {
                object obj = this.ViewState["ContentID"];
                if (obj == null)
                    return Guid.Empty;
                return (Guid)obj; 
            }
            set
            {
                this.ViewState["ContentID"] = value;
            }
        }
     
    }


    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. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    29 Jun 2010
    Link to this post
    Hey,
    Thanks a ton. This is what exactly i required. I managed to tweak this as per my requirement for getting the generic content. The code for the same is as below:
    public class ContentIDWebEditor : WebUITypeEditor<Guid>
    {

        private ITemplate template;
        private ContentManager contentManager;

        // TEMPLATE PATH  
        public string Template
        {
            get
            {
                object o = this.ViewState["Template"];
                if (o == null)
                    return ("~/Sitefinity/UserControls/CustomControls/CustomWebUIEditor.ascx");
                return (string)o;
            }
            set
            {
                this.ViewState["Template"] = value;
            }
        }

        // CONTROL REFERENCE TO RADTREEVIEW CONTROL 
        protected virtual RadTreeView TreeView
        {
            get
            {
                return this.Controls[0].FindControl("RadTreeView1") as RadTreeView;
            }
        }

        public override Guid Value
        {
            get
            {
                Guid contentId = Guid.Empty;
                if (TreeView.SelectedNode != null)
                    contentId = new Guid(TreeView.SelectedNode.Value);
                if (contentId != Guid.Empty)
                    return ((IContent)contentManager.GetContent(contentId)).ID;
                return Guid.Empty;
            }
            set
            {
                this.ViewState["selectedPage"] = value;
            }
        }

    public ContentIDWebEditor()
    {
    //
    // TODO: Add constructor logic here
    //
    }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            this.contentManager = new ContentManager();
            this.template = ControlUtils.GetTemplate<SelectorTemplate>(this.Template);
            this.template.InstantiateIn(this);
            RadTreeNode root = new RadTreeNode();
            root.Value = Guid.Empty.ToString();
            root.Text = "All Content";
            root.Expanded = true;
            TreeView.Nodes.Add(root);
            this.LoadNodes(root);
        }

        //HELPER METHOD FOR LOADING OUR NODES 
        private void LoadNodes(RadTreeNode root)
        {
            ContentManager cManager = new ContentManager();
            foreach (CmsContentBase page in cManager.GetContent())
            {
                RadTreeNode node = new RadTreeNode();
                node.Value = page.ID.ToString();
                node.Expanded = true;
                node.Text = page.GetMetaData("Name").ToString();
                node.ToolTip = page.GetMetaData("Name").ToString();
                root.Nodes.Add(node);
            }

        }

        public class SelectorTemplate : ITemplate
        {
            public void InstantiateIn(Control container)
            {
            }
        }

    }


    Place the code below code in the User Control:

    [WebEditor("ContentIDWebEditor, App_Code")]
        public Guid ContentID
        {
            get
            {
                object obj = this.ViewState["ContentID"];
                if (obj == null)
                    return Guid.Empty;
                return (Guid)obj;
            }
            set
            {
                this.ViewState["ContentID"] = value;
            }
        } 

    register the user control for treeview with the following code in the web.config file above the closing tag of toolboxControls
    <add name="Web UI View" section="Generic Content" url="~/Sitefinity/UserControls/CustomControls/CustomWebUIEditor.ascx" />


    Code to be placed in "CustomWebUIEditor.ascx":
    <telerik:RadTreeView ID="RadTreeView1" runat="server" Skin="Black" />

    Thats it and u are done.
    But please note that the user control location should be correct by setting the template property in ContentIDWebEditor.cs file


    Thanks once again!!!!!

    And the needy, Njoy.


    Cheers!!!!!


    Regards,
    Siddesh Kapadi
Register for webinar
3 posts, 0 answered