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

Forums / Developing with Sitefinity / Allow user to select a single category

Allow user to select a single category

4 posts, 0 answered
  1. UI Crew
    UI Crew avatar
    151 posts
    Registered:
    27 Sep 2012
    18 Dec 2008
    Link to this post
    Hi,

    I have a generic content provider called "Data". In a user control I have a property called "SelectedCategory" and want to allow the content manager to select a single category from the list of categories in the Data provider.

    Is there a WebEditor that allows this and how can I use it.

    Cheers,
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    18 Dec 2008
    Link to this post
    Hi Seth Cleaver,

    Sitefinity does not provide a selector for choosing a single category. We would suggest you use CategoriesSelector property editor that lets the user choose more that one categories:

    [WebEditor("Telerik.Cms.Engine.WebControls.Categories.CategoriesSelector, Telerik.Cms.Engine")] 
    [TypeConverter("Telerik.Cms.Engine.WebControls.Categories.SelectedCategoriesConverter, Telerik.Cms.Engine")] 
    public virtual string[] SelectedCategories 
        get 
        { 
            return selectedCategories; 
        } 
        set 
        { 
            selectedCategories = value; 
        } 

    Actually, you could achieve the required functionality (to select a single category) by implementing the following javascript function in the CategoriesSelector template (\[Project_Name]\Sitefinity\Admin\ControlTemplates\Generic_Content\CategoriesSelector.ascx):

    <h4 class="multyhead">Categories selector</h4> 
    <div class="selectedItems" id="availableItems"
    <asp:GridView ID="categoriesList" runat="server" AutoGenerateColumns="false" AllowPaging="false" GridLines="None" ShowHeader="false"
        <Columns> 
            <asp:TemplateField> 
                <ItemTemplate> 
                    <asp:CheckBox ID="categorySelectedCheckbox" runat="server" onclick="selectChkBox('availableItems', this);" /> 
                </ItemTemplate> 
                <ItemStyle CssClass="gridActionsSelectCategory" /> 
            </asp:TemplateField> 
            <asp:BoundField DataField="CategoryName" SortExpression="CategoryName" HeaderText='<%$Resources:Category %>' /> 
        </Columns> 
    </asp:GridView> 
    </div> 
     
    <script language="javascript"
    function selectChkBox(availableItems, obj) 
        var availableTags = document.getElementById(availableItems); 
        var tagList = availableTags.getElementsByTagName("input"); 
         
        for (i = 0; i < tagList.length; i++) { 
          tagList[i].checked = false
        } 
        obj.checked = true
    </script> 

    Hope this helps.

    Sincerely yours,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Devin
    Devin avatar
    149 posts
    Registered:
    09 Jun 2009
    09 Jun 2010
    Link to this post
    Hi Pepi,
    Is there a similar control for News categories?

    Thanks!
    Devin
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Jun 2010
    Link to this post
    Hi Devin,

    You need to create a custom WebUITypeEditor and get the categories by provider using GetCategories method of the manger.

    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.
Register for webinar
4 posts, 0 answered