ItemDataBound event in Dynamic Treeview

2 posts, 0 answers
  1. Prabhu
    Prabhu avatar
    8 posts
    Member since:
    Jan 2012

    Posted 20 Mar 2012 Link to this post

    Hi,
     Based on certain criteria Im binding items in RadMenu, in which am supposed to populate the RadTreeView inside one of the RadMenuItem (named "Tools") dynamically. Ive done this using ItemDataBound of RadMenu. (below is the Code)  :      
    protected void TopMenu_ItemDataBound(object sender, RadMenuEventArgs e)
    {
        if (!string.IsNullOrEmpty(e.Item.NavigateUrl))
            e.Item.Attributes["onclick"] = "return Redirect(this.href);";
     
        if (e.Item.Text.ToLower() == "Tools".ToLower())
        {
            RadMenuItem radTools = new RadMenuItem();
     
            RadTreeView radToolTreeView = new RadTreeView();
            radToolTreeView.DataTextField = "Text";
            radToolTreeView.DataFieldID = "MenuID";
            radToolTreeView.DataFieldParentID = "ParentID";
            radToolTreeView.DataNavigateUrlField = "Url";
            radToolTreeView.LoadingMessage = "Loading...";               
            radToolTreeView.Skin = "Web20";
            radToolTreeView.CssClass = "MenuTreeView";   
            radToolTreeView.DataSource = BindToolMenu1();
            radToolTreeView.BackColor = System.Drawing.Color.Aqua;   
            radToolTreeView.DataBind();
            radToolTreeView.ExpandAllNodes();
            radTools.Controls.Add(radToolTreeView);
     
            e.Item.Items.Add(radTools);
        }
    }

    from the above code, I am able to set the attributes for RadMenuItem

    e.Item.Attributes["onclick"] = "return Redirect(this.href);";

    I need to set the same attribute on clicking on TreeViewNode. Please tell me how to do this?

    Thanks in advance
    KSP
  2. Prabhu
    Prabhu avatar
    8 posts
    Member since:
    Jan 2012

    Posted 20 Mar 2012 Link to this post

    hi,
       Ive accomplish that task by adding below code.
    protected void TopMenu_ItemDataBound(object sender, RadMenuEventArgs e)
     {
         if (!string.IsNullOrEmpty(e.Item.NavigateUrl))
             e.Item.Attributes["onclick"] = "return Redirect(this.href);";
     
         if (e.Item.Text.ToLower() == "Tools".ToLower())
         {
             RadMenuItem radTools = new RadMenuItem();
     
             RadTreeView radToolTreeView = new RadTreeView();
             radToolTreeView.NodeDataBound += new RadTreeViewEventHandler(treeview_click);
             radToolTreeView.DataTextField = "Text";
             radToolTreeView.DataFieldID = "MenuID";
             radToolTreeView.DataFieldParentID = "ParentID";
             radToolTreeView.DataNavigateUrlField = "Url";               
             radToolTreeView.LoadingMessage = "Loading...";
             radToolTreeView.Skin = "Web20";
             radToolTreeView.CssClass = "MenuTreeView";
             radToolTreeView.DataSource = BindToolMenu1();
             radToolTreeView.BackColor = System.Drawing.Color.Aqua;
             radToolTreeView.DataBind();
             radToolTreeView.ExpandAllNodes();               
             radTools.Controls.Add(radToolTreeView);
     
             e.Item.Items.Add(radTools);
         }
     }
     
     protected void treeview_click(object sender, RadTreeNodeEventArgs e)
     {
         if (!string.IsNullOrEmpty(e.Node.NavigateUrl))
             e.Node.Attributes["onclick"] = "return Redirect(this.href);";
     }

    Thanks a lot....
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top