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

Forums / Developing with Sitefinity / Customising Generic Content with new Category MetaFields

Customising Generic Content with new Category MetaFields

5 posts, 1 answered
  1. Mark
    Mark avatar
    12 posts
    Registered:
    10 Feb 2011
    10 Feb 2011
    Link to this post
    Hi all,

    I'm failry new to Sitefinity and have started to add custom fields to the generic content module.  With the help of this forum I have been able to proceed without too much trouble.  I have a requirement to add a custom category field which is filtered in some way.  Ideally I would like to be able to reuse as much out of the box code as possible.  Looking at ContentEditView.ascx I have added a new metafield called Category1 as you will see in the code snippit below.  It would be really nice if <sf:ContentCategoriesField  ID="Category1" runat="server" /> had another attribute called something like "RootCategory" where you could specify the root category that would inturn return the subcategories in the dropdown list that is bound to this control.  Is there something else that could do something like this or could you please suggest the best way to approach this, i.e. write my own control, specifiy a "ProviderName" attribute etc...

    Thanks in advance
    Mark

    <h3>
        <asp:Literal ID="Literal1" runat="server" Text="Category1"></asp:Literal></h3>
    <fieldset class="set">
        <ol class="setIn">
            <li class="catSel clearfix">
                <asp:Label ID="Label1" AssociatedControlID="Category1" runat="server">
                    <asp:Literal ID="Literal1" runat="server" Text="Category1"></asp:Literal>
                    <em id="Em1" runat="server"></em></asp:Label>
                <sf:ContentCategoriesField ID="Category1" runat="server" />
            </li>
        </ol>
    </fieldset>
    <div class="bottom"><div><!-- --></div></div>


    Category 1
     - Category 1.1
     - Category 1.2
     - Category 1.3
    Category 2
     - Category 2.1
     - Category 2.2
    etc...
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Feb 2011
    Link to this post
    Hello Mark,

    Actually ContentCategoriesField will give you a list of all categories and this control will not show you hierarchical structure. One of the solution here is creating a custom control that implements ITextControl and use RadComboBox that wraps RadTreeview with a template which is bound to all categories.

    If you want to have two RadComboBox controls, again you need a custom control. It is better to use one control that wraps two RadComboBox controls. You can bind the first control and subscribe for SelectedIndexChanged where you can bind the second control

    ICategory rootCategory = Manager.GetCategory(RootCategory);
    categories = Manager.GetCategoriesTree(rootCategory);

    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
  3. Mark
    Mark avatar
    12 posts
    Registered:
    10 Feb 2011
    11 Feb 2011
    Link to this post
    Hi Ivan,

    Thanks for posting back to me.  This sounds good in theory so I will have a try.  Anychance you can help me in getting started with a code example?

    I don't think I made myself 100% clear in the first post.  What I have done is added a number of categories to sitefinity using the standard interface.  I would like to add 2 extra category dropdowns to the generic content items.  The first will list all categories under the top category of "Category 1" and the 2nd will list all categories under the top category of "Category 2".  None of "Category 1's" sub categories will appear in the dropdown list for Category 2 and likewise for the other dropdowns.  If the need arises to add an extra metafield say Category 3, I should be able to easily add this and more.  I hope that helps explain what I am trying to achieve clearer.

    Also is it possible to allow multiple selection of categories?  Whould it be better to present the catagories as checkboxes and allow the user to select multiple that way?

    Cheers
    Mark
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Feb 2011
    Link to this post
    Hello Mark,

    You can generate the RadComboBox controls at runtime, since registering custom metakeys does not require to add the filelds in the web.config. Generally you need one control which elements are dynamically created and you need to bind it at runtime depending on the levels that you want to show. Also you should use an Update Panel or make a post back.

    Each category has property ParentCategoryID, so you can easily populate the first RadCombobox. After you select an item and force post back you have to add a new RadComboBox and populate it with the items from the first category ( if there are any).

    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
    Answered
  5. Mark
    Mark avatar
    12 posts
    Registered:
    10 Feb 2011
    21 Feb 2011
    Link to this post
    Cool, thanks for your help, I have this working now
Register for webinar
5 posts, 1 answered