Rad tree view :Binding custom attributes

2 posts, 1 answers
  1. piyush
    piyush avatar
    3 posts
    Member since:
    Apr 2009

    Posted 09 Jul 2009 Link to this post

    I have following columns in my datasource which is a Generic list

    Element ID
    ParentElementID
    Element Name
    Sequence
    Layer

    I need to create and bind  custom attributes like Layer,Sequence,etc from the datasource so that I can manipulate them at Nodedatabound event .
    Also for several childs of parent node
    I need to order the sequence of nodes on the basis of Sequence .


  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Jul 2009 Link to this post

    Hi Piyush,

    Checkout the following example which shows how to add custom attributes in NodeDataBound event.

    ASPX:
     
    <telerik:RadTreeView ID="RadTreeView2" runat="server" DataFieldID="CategoryID" DataSourceID="SqlDataSource1" 
        DataTextField="CategoryID" OnNodeDataBound="RadTreeView2_NodeDataBound" OnNodeClick="RadTreeView2_NodeClick"
    </telerik:RadTreeView> 

    C#:
     
    protected void RadTreeView2_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e) 
        DataRowView dataSourceRow = (DataRowView)e.Node.DataItem; 
        //set custom attributes from the datasource:   
        e.Node.Attributes["CategoryName"] = dataSourceRow["CategoryName"].ToString();   
    protected void RadTreeView2_NodeClick(object sender, RadTreeNodeEventArgs e) 
        String Name = e.Node.Text.ToString(); 
        String CategoryName = RadTreeView2.SelectedNode.Attributes["CategoryName"]; 
        Response.Write("You have selected " + Name + " with Name " + CategoryName);   

    -Shinu.
Back to Top