Set NavigateUrl dinamically

2 posts, 0 answers
  1. Bruno
    Bruno avatar
    20 posts
    Member since:
    Feb 2012

    Posted 06 Mar 2012 Link to this post

    Hi everybody, i created, a site map dinamically, but all the nodes assume tha same navigateUrl.

    Is possible to make that dinamically ? if so, how?
    thnkz
    <telerik:RadSiteMap runat="server" ID="RadSiteMap1"
        DataFieldID="ID" DataFieldParentID="ParentID" DataTextField="Text" ShowNodeLines="true">
        <DataBindings>
            <telerik:RadSiteMapNodeBinding NavigateUrl="#" />
        </DataBindings>
    </telerik:RadSiteMap>
    protected void Page_Load(object sender, EventArgs e)
           {
               RadSiteMap1.DataSource = SiteDataItem.GetSiteData();
               RadSiteMap1.DataBind();
           }
           /// <summary>
           /// Método que encapsula os atributos e monta a lista.
           /// </summary>
           public class SiteDataItem
           {
               private string _text;
               private int _parentId;
               private int prvID;
               private string prvLink;
     
               /// <summary>
               /// Descrição dos nodes
               /// </summary>
               public string Text
               {
                   get { return _text; }
                   set { _text = value; }
               }
               /// <summary>
               /// ID do node
               /// </summary>
               public int ID
               {
                   get { return prvID; }
                   set { prvID = value; }
               }
               /// <summary>
               /// ID de node pai
               /// </summary>
               public int ParentID
               {
                   get { return _parentId; }
                   set { _parentId = value; }
               }
               /// <summary>
               /// Atribui valor aos campos.
               /// </summary>
               /// <param name="ID"></param>
               /// <param name="nivel0"></param>
               /// <param name="nivel1"></param>
               /// <param name="nivel2"></param>
               /// <param name="nivel3"></param>
               /// <param name="nivel4"></param>
               /// <param name="text"></param>
               /// int ID, int nivel0, int nivel1, int nivel2, int nivel3, int nivel4,
               public SiteDataItem(int id, int parentId, string text)
               {
                   //prvNivel0 = nivel0;
                   //prvNivel1 = nivel1;
                   //prvNivel2 = nivel2;
                   //prvNivel3 = nivel3;
                   //prvNivel4 = nivel4;
                   prvID = id;
                   _parentId = parentId;
                   _text = text;
               }
               /// <summary>
               /// Monta a lista TreeView.
               /// </summary>
               /// <returns>Lista com dados TreeView.</returns>
               public static List<SiteDataItem> GetSiteData()
               {
                   List<SiteDataItem> siteData = new List<SiteDataItem>();
     
                   siteData.Add(new SiteDataItem(1, 0, "Products"));
                   siteData.Add(new SiteDataItem(2, 1, "RadControls for ASP.NET Ajax"));
                   siteData.Add(new SiteDataItem(3, 1, "RadControls for Silverlight"));
                   siteData.Add(new SiteDataItem(4, 2, "RadGrid"));
                   siteData.Add(new SiteDataItem(5, 2, "RadScheduler"));
                   siteData.Add(new SiteDataItem(6, 2, "RadEditor"));
                   siteData.Add(new SiteDataItem(7, 3, "RadGrid"));
                   siteData.Add(new SiteDataItem(8, 3, "RadMenu"));
                   siteData.Add(new SiteDataItem(9, 3, "RadEditor"));
     
                   return siteData;
               }
           }
  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 09 Mar 2012 Link to this post

    Hello Bruno,

    Yes, you can handle NodeDataBound to set any additional properties using the DataItem object. Here is an example:
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RadSiteMap1.DataSource = SiteDataItem.GetSiteData();
     
            RadSiteMap1.DataBind();
                 
        }
        protected void RadSiteMap1_NodeDataBound(object sender, RadSiteMapNodeEventArgs e)
        {
            e.Node.NavigateUrl = (e.Node.DataItem as SiteDataItem).Url;
        }
    }
     
    public class SiteDataItem
    {
     
        private string _text;
        private string _url;
     
        private int _parentId;
     
        private int prvID;
     
        private string prvLink;
     
     
     
        /// <summary>
     
        /// Descrição dos nodes
     
        /// </summary>
     
        public string Text
        {
     
            get { return _text; }
     
            set { _text = value; }
     
        }
     
        public string Url
        {
     
            get { return _url; }
     
            set { _url = value; }
     
        }
     
        /// <summary>
     
        /// ID do node
     
        /// </summary>
     
        public int ID
        {
     
            get { return prvID; }
     
            set { prvID = value; }
     
        }
     
        /// <summary>
     
        /// ID de node pai
     
        /// </summary>
     
        public int ParentID
        {
     
            get { return _parentId; }
     
            set { _parentId = value; }
     
        }
     
        /// <summary>
     
        /// Atribui valor aos campos.
     
        /// </summary>
     
        /// <param name="ID"></param>
     
        /// <param name="nivel0"></param>
     
        /// <param name="nivel1"></param>
     
        /// <param name="nivel2"></param>
     
        /// <param name="nivel3"></param>
     
        /// <param name="nivel4"></param>
     
        /// <param name="text"></param>
     
        /// int ID, int nivel0, int nivel1, int nivel2, int nivel3, int nivel4,
     
        public SiteDataItem(int id, int parentId, string text, string url)
        {
     
            //prvNivel0 = nivel0;
     
            //prvNivel1 = nivel1;
     
            //prvNivel2 = nivel2;
     
            //prvNivel3 = nivel3;
     
            //prvNivel4 = nivel4;
     
            prvID = id;
     
            _parentId = parentId;
     
            _text = text;
     
            _url = url;
     
        }
     
        /// <summary>
     
        /// Monta a lista TreeView.
     
        /// </summary>
     
        /// <returns>Lista com dados TreeView.</returns>
     
        public static List<SiteDataItem> GetSiteData()
        {
     
            List<SiteDataItem> siteData = new List<SiteDataItem>();
     
     
     
            siteData.Add(new SiteDataItem(1, 0, "Products", "http://www.telerik.com"));
     
            siteData.Add(new SiteDataItem(2, 1, "RadControls for ASP.NET Ajax", "http://www.telerik.com"));
     
            siteData.Add(new SiteDataItem(3, 1, "RadControls for Silverlight", "http://www.telerik.com"));
     
            siteData.Add(new SiteDataItem(4, 2, "RadGrid", "http://www.telerik.com"));
     
            siteData.Add(new SiteDataItem(5, 2, "RadScheduler", "http://www.telerik.com"));
     
            siteData.Add(new SiteDataItem(6, 2, "RadEditor", "http://www.telerik.com"));
     
            siteData.Add(new SiteDataItem(7, 3, "RadGrid", "http://www.telerik.com"));
     
            siteData.Add(new SiteDataItem(8, 3, "RadMenu", "http://www.telerik.com"));
     
            siteData.Add(new SiteDataItem(9, 3, "RadEditor", "http://www.telerik.com"));
     
     
     
            return siteData;
     
        }
     
    }

    Note, that you have to extend your class to expose the Url property.


    Regards,
    Peter
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top