This is a migrated thread and some comments may be shown as answers.

Treeview with folder icon

3 Answers 94 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mugdha Aditya
Top achievements
Rank 1
Mugdha Aditya asked on 24 Mar 2012, 06:23 AM
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

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 26 Mar 2012, 05:18 AM
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.
0
Mugdha Aditya
Top achievements
Rank 1
answered on 26 Mar 2012, 08:30 AM
Thaks a lot princy.. it resolved my problem :).
0
Bozhidar
Telerik team
answered on 26 Mar 2012, 09:25 AM
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.
Tags
TreeView
Asked by
Mugdha Aditya
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Mugdha Aditya
Top achievements
Rank 1
Bozhidar
Telerik team
Share this question
or