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

Forums / Developing with Sitefinity / Blog Categories Dropdown

Blog Categories Dropdown

3 posts, 0 answered
  1. ddblee
    ddblee avatar
    20 posts
    Registered:
    24 Jul 2008
    23 Sep 2008
    Link to this post
    I would like to modify ~/Sitefinity/ControlTemplates/Blogs/CategoriesList.ascx to present the Blog categories in a dropdown list instead of the default <ul>

    What would be the best way to go about doing this?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Sep 2008
    Link to this post
    Hello ddblee,

    CategoriesList public control does not provide the required functionality. So you need to create your own control using Categories API. Here is a simple example how to get all categories for the Blogs module:

    .ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="drop.ascx.cs" Inherits="Sitefinity_UserControls_drop" %> 
     
     
    <asp:DropDownList ID="categorylist" runat="server"></asp:DropDownList> 

    .ascx.cs

    using System; 
    using System.Collections; 
    using System.Configuration; 
    using System.Data; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using Telerik.Cms.Engine; 
     
    public partial class Sitefinity_UserControls_drop : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
            { 
                Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager("Blogs"); 
                // create a list of all categories 
                IList listOfCategories = contentManager.GetCategories(); 
              
                this.categorylist.DataSource = listOfCategories; 
                this.categorylist.DataTextField = "CategoryName"
                this.categorylist.DataValueField = "ID"
                this.categorylist.DataBind(); 
            } 
     
        } 

    Hope this helps.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. ddblee
    ddblee avatar
    20 posts
    Registered:
    24 Jul 2008
    25 Sep 2008
    Link to this post
    Thanks! That's got me going.

Register for webinar
3 posts, 0 answered