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

Can i customize Databound treeView?

1 Answer 60 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
visionXpert
Top achievements
Rank 1
visionXpert asked on 14 Jun 2012, 10:30 PM
I checked out the examples, and every time i see the examples where you can put an image on a node they're not databound examples.

Hi there, this is my first time playing with Telerik controls, just bought an expensive all inclusive package.. now i need to show my employer what i can do...

What i'm in the process of building is a tree of report links

Ie:
Reports
-Sales
--Sales Report 1
--Sales Report 2
-Accounting
--Acc Report 1
--Acc Report 2

now i want to build the tree from a table in my DB, and that's working fine when i bind... but
i'd like the final nodes (ie: Sales Report1, or Acc Report 1) to be shown with icons infront of them, and have a dynamic link built to each of the report nodes.

my code on page load -
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * From Reports", ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString);
        DataSet links = new DataSet();
        adapter.Fill(links);
        RadTreeView1.DataTextField = "Description";
        RadTreeView1.DataFieldID = "ID";
        RadTreeView1.DataFieldParentID = "ParentID";
        RadTreeView1.DataNavigateUrlField = "ReportLink";
        RadTreeView1.DataSource = links;
        RadTreeView1.DataBind();
        RadTreeView1.ExpandAllNodes();

this works great... loads the nodes, but now i want to start modifying the way each node looks, for example, the "Report" parent node i'd like to have no icons, then the nodes: "Sales" and "Accounting" to have for example a folder icon and the final nodes such as "Sales Report 1" or "Acc Report 1" to have different icons...

Can i achieve this with the above databinding? or do i have to Add items to my Treeview as i parse through my Dataset?

Also,
The links to each of the report nodes i want the "ReportLink" value thats assigned to "DataNavigateUrlField" to be dynamically different based on other tables i have in my DB....
here is an example of a report link: "http://mysite.com/report1.aspx?Param1=value1&Param2=value2"
and another may be "http://mysite.com/reportAccReport.aspx?Param1=value1&Param2=value2&Param3=value3"

where i'd like to build logic to fill in the "valueX" parameters.

Any suggestions/help would be much appreciated

1 Answer, 1 is accepted

Sort by
0
visionXpert
Top achievements
Rank 1
answered on 14 Jun 2012, 11:24 PM
figured out the icons like this

        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * From Reports", ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString);
        DataSet links = new DataSet();
        adapter.Fill(links);
        RadTreeView1.DataTextField = "Description";
        RadTreeView1.DataFieldID = "ID";
        RadTreeView1.DataFieldParentID = "ParentID";
        RadTreeView1.DataNavigateUrlField = "ReportLink";
        RadTreeView1.DataSource = links;
        RadTreeView1.DataBind();
        foreach (RadTreeNode node in RadTreeView1.GetAllNodes())
        {
            if (node.NavigateUrl.Length>0)
                node.ImageUrl = "images/Vista/asmx.png";
            else
                node.ImageUrl = "images/Outlook/folder.gif";
        }
        RadTreeView1.ExpandAllNodes();
    }

i'll post further questions on this topic as they arise... now will dig deeper before posting.. thanks
Tags
TreeView
Asked by
visionXpert
Top achievements
Rank 1
Answers by
visionXpert
Top achievements
Rank 1
Share this question
or