Treeview with folder icon

4 posts, 1 answers
  1. Mugdha Aditya
    Mugdha Aditya avatar
    71 posts
    Member since:
    Mar 2010

    Posted 24 Mar 2012 Link to this post

    Hello,

    Am having radtreeview on my webpage for which i want to add folder icon before every node.
    how to achieve that?

     

     

    <telerik:RadTreeView ID="RadTreeViewSource" runat="server" Height="580px"

     

     

     

    OnNodeClick="RadTreeViewSource_NodeClick" >

     

     

     

    <DataBindings>

     

     

     

    <telerik:RadTreeNodeBinding Expanded="false" />

     

     

     

    </DataBindings>

     

     

     

    </telerik:RadTreeView>

    Above is my code.
    am binding treeview in codebehind with datattable value.

    Thanks,
    Mugdha

     

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Mar 2012 Link to this post

    Hello,

    Try the following code which helps to loop through each node and add the ImageUrl.
    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" runat="server" Width="300px" Height="250px" OnPreRender="RadTreeView1_PreRender">
     <DataBindings>
      <telerik:RadTreeNodeBinding Expanded="True" />
     </DataBindings>
    </telerik:RadTreeView>
    C#:
    protected void RadTreeView1_PreRender(object sender, EventArgs e)
     {
      SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM tree",ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
      DataTable links = new DataTable();
      adapter.Fill(links);
      RadTreeView1.DataTextField = "name";
      RadTreeView1.DataFieldID = "id";
      RadTreeView1.DataFieldParentID = "parent";
      RadTreeView1.DataSource = links;
      RadTreeView1.DataBind();
      foreach (RadTreeNode node in RadTreeView1.GetAllNodes())
       {
        node.ImageUrl = "~/Images/folder.gif";
       }
     }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mugdha Aditya
    Mugdha Aditya avatar
    71 posts
    Member since:
    Mar 2010

    Posted 26 Mar 2012 Link to this post

    Thaks a lot princy.. it resolved my problem :).
  5. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 26 Mar 2012 Link to this post

    Hello Mugdha,

    If you need the same icon to appear before every node, you can just put it in the DataBindings section of the treeview and avoid looping through all nodes. Like so:
    <DataBindings>
        <telerik:RadTreeNodeBinding ImageUrl="Folder.jpg" />
    </DataBindings>
     
    Regards,
    Bozhidar
    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.
Back to Top