More in this section

Forums / Developing with Sitefinity / How to: Populate dropDown with page name

How to: Populate dropDown with page name

14 posts, 0 answered
  1. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    24 Nov 2009
    Link to this post
    Hellou to all,
    well I have one problem.
    Let's explain:

    I want to create six pages,

    Page1 - show in navigation,
    Page2 - show in navigation,
    Page3 - show in navigation,

    Page4 - don't show in navigation, but populate name of page into dropdown list
    Page5 - don't show in navigation, but populate name of page into dropdown list
    Page6 - don't show in navigation, but populate name of page into dropdown list

    Any idea how can I do this?
    I hope you understand me, any suggestion will help me.
    Best regards,
    Milos.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Nov 2009
    Link to this post
    Hello Milos Tadic,

    Below is a sample code that will populate RadComboBox with all pages that are not shown in navigation.

    CmsManager Manager = new CmsManager();
    IList listOfAll = Manager.GetPages();
    foreach(ICmsPage page in listOfAll)
    {
        if(!page.Navigable)
        {
            RadComboBoxItem item = new RadComboBoxItem(page.MenuName);
            combo.Items.Add(item);
        }
    }

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    24 Nov 2009
    Link to this post
    Thanks for quick answer, but can I populate with specific page?
    I have many pages that are not listed in navigation, I don't want to populate combox with all this pages.

    I hope you understand me what I mean.

    Best regards,
    Milos.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Nov 2009
    Link to this post
    Hello Milos Tadic,

    Then the page you want to use for the RadComboBox control. You can find more information at Finding Pages

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    24 Nov 2009
    Link to this post
    Well, that is good idea, but have some little problem with radcomboBox

    On my master page I added combo box:

    <telerik:RadComboBox ID="RadComboBoxTest" runat="server" Height="200px" Width="200px"
                                DropDownWidth="298px" EmptyMessage="Choose" HighlightTemplatedItems="true"
                                EnableLoadOnDemand="true" ></telerik:RadComboBox>

    Then, when I use RadComboBoxTest.Items (............)  on my page.master.cs, I got messages
    "The name RadComboBoxTest does not exist in the current context".
    Sorry I'm new with C# and Sitefinity CMS.

    Thanks a lot.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Nov 2009
    Link to this post
    Hi Milos Tadic,

    The error says that the RadComboBox control cannot be found.  You can give a try to the following sample:

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="SimpleMaster.master.cs" Inherits="App_Master_SimpleMaster" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <asp:ContentPlaceHolder id="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
          <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
            <telerik:RadComboBox ID="RadComboBoxTest" runat="server"
                Height="200px"
                Width="200px"
                DropDownWidth="298px"
                EmptyMessage="Choose"
                HighlightTemplatedItems="true"
                EnableLoadOnDemand="true">
            </telerik:RadComboBox>
          </asp:ContentPlaceHolder>
        </div>
        </form>
    </body>
    </html>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    public partial class App_Master_SimpleMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RadComboBoxItem item = new RadComboBoxItem("test");
            RadComboBoxTest.Items.Add(item);
        }
    }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    24 Nov 2009
    Link to this post
    Hey Ivan, thanks, it's work. One more question:
    When I click on item in comboBox (in this case page ), I want to browser redirect to that page ?

    Thanks,
    Milos.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Nov 2009
    Link to this post
    Hi Milos Tadic,

    You can subscribe for SelectedIndexChanged event and perform an redirect. You can set the item.Value to the page url and then inside SelectedIndexChanged you can call Response.Redirect(e.Value); Another option could be creating an Hyperlink inside RadCombobox template and then setting in the same way the text and NavigateUrl of this link to page MenuName and Url

    Sample:

    protected void Page_Load(object sender, EventArgs e)
    {
        RadComboBoxTest.AutoPostBack = true;
        RadComboBoxItem zero = new RadComboBoxItem("-Choose from the items below-");
        RadComboBoxTest.Items.Add(zero);
        RadComboBoxItem item = new RadComboBoxItem("telerik", "http://www.telerik.com");
        RadComboBoxTest.Items.Add(item);
        RadComboBoxItem item1 = new RadComboBoxItem("sitefinity", "http://www.sitefinity.com");
        RadComboBoxTest.Items.Add(item1);
        RadComboBoxTest.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(RadComboBoxTest_SelectedIndexChanged);
    }
     
    void RadComboBoxTest_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Response.Redirect(e.Value);
    }


    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    24 Nov 2009
    Link to this post
    Thanks a lot, that's it :-)

    Best regards,
    Milos.
  10. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    25 Nov 2009
    Link to this post
    Hello folks,
    well I have a little problem:

    For now we use this code-behind to retrive pages but this is not enought because this code get all child pages of a parent page

    1 protected void Page_Load(object sender, EventArgs e) 
    2     { 
    3          RadComboBoxItem zero1 = new RadComboBoxItem("-Izaberite nedelju-"); 
    4     week.Items.Add(zero1); 
    5     // create a new instance of CmsManager 
    6     Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager(); 
    7     // get the current node of sitemap 
    8     Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode; 
    9     Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage; 
    10     Guid currentPageId = currentPage.ID; 
    11     IList childPage = cmsManager.GetPages(currentPageId); 
    12     foreach (ICmsPage page in childPage) 
    13     { 
    14          
    15             week.AutoPostBack = true
    16              
    17             RadComboBoxItem item11 = new RadComboBoxItem(page.MenuName, page.StaticUrl); 
    18             week.Items.Add(item11); 
    19             week.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(week_SelectedIndexChanged); 
    20  
    21          
    22     } 
    23  
    24         
    25        } 
    26     void week_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
    27
    28     Response.Redirect(e.Value); 
    29
    30     } 

    I need somewhere to write in code pageName to populate comboBox with their child pages.
    For example:

    Home
     -subpage1
     -subpage2

    Forum
     -forumsubpage1
     -forumsubage2

    On same page I want several comboBoxes

    RadComboBox1 -----> populate with Home child pages (in this case that will be subpage1 and subpage2)
    RadComboBox2 -----> populate with Forum child pages (in this case that will be forumsubpage1 and forumsubpage2)

    Any suggestion will be appreciated,
    Milos.
     



  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Nov 2009
    Link to this post
    Hello Milos Tadic,

    You need to create item template and embed a control inside it. Then bind the control in ItemTemplate to list of all pages

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="SimpleMaster.master.cs" Inherits="App_Master_SimpleMaster" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <asp:ContentPlaceHolder id="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
          <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
            <telerik:RadComboBox ID="RadComboBox1" runat="server">
            <Items>
                <telerik:RadComboBoxItem runat="server" Text="-TEST-" />
            </Items>
            <ItemTemplate>
              <telerik:RadTreeView ID="RadTreeView1" runat="server"></telerik:RadTreeView>
            </ItemTemplate>
            </telerik:RadComboBox>
          </asp:ContentPlaceHolder>
        </div>
        </form>
    </body>
    </html>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using Telerik.Cms;
    using System.Collections;
     
    public partial class App_Master_SimpleMaster : System.Web.UI.MasterPage
    {
     
     
     
        protected void Page_Load(object sender, EventArgs e)
        {
            RadTreeView tree = (RadTreeView)RadComboBox1.Items[0].FindControl("RadTreeView1");
            if (tree != null)
            {
                tree.NodeDataBound += new RadTreeViewEventHandler(tree_NodeDataBound);
                LoadNodes();
             
            }
        }
     
        void tree_NodeDataBound(object sender, RadTreeNodeEventArgs e)
        {
            ICmsPage p = (ICmsPage)e.Node.DataItem;
            e.Node.ToolTip = p.MenuName;
        }
     
        private void LoadNodes()
        {
            RadTreeView tree = (RadTreeView)RadComboBox1.Items[0].FindControl("RadTreeView1");
            CmsManager manager = new CmsManager();
            IList AllPages = manager.GetPages();
            var newColl = AllPages.Cast<ICmsPage>().ToList();
            // newColl.Sort((x, y) => x.MenuName.CompareTo(y.MenuName));
            tree.DataTextField = "MenuName";
            tree.DataFieldID = "ID";
            tree.DataFieldParentID = "ParentID";
            tree.DataNavigateUrlField = "StaticUrl";
            tree.DataSource = newColl;
            tree.DataBind();
        }
     
     
    }


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  12. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
    25 Nov 2009
    Link to this post
    Hm, I still got all pages, but in treeview :-S
    I thought something like this: getAllchildpage by pageName ("Home") ---->comboBox1
                                                 getAllchildpage by pageName ("Forum") ---->comboBox2, etc, etc......

    Scenario should be :

    Combo1   -Choose-
                    -SubPageHome1
                    -SubPageHome2

    Combo2   -Choose-
                    -SubPageForum1
                    -SubPageForum2

    It should be somewhere that defines the name of the page that we want to populate comboBox with child pages.
    I hope you understand what I wanted to say.
    Best regards,
    Milos.
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Nov 2009
    Link to this post
    Hi Milos Tadic,

    Subscribe for RadTreeView NodeDataBound event and cast the node as CmsSiteMapNode. Then bind only nodes that you want and its children to the RadTreeView. You can use recursion and group the items using its ParentID- where Home and Forum are parent nodes.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  14. Milos Tadic
    Milos Tadic avatar
    32 posts
    Registered:
    05 Nov 2009
Register for webinar
14 posts, 0 answered