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

setting node's target lin k in C#

2 Answers 54 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Aarsh
Top achievements
Rank 1
Aarsh asked on 20 Jul 2012, 03:39 AM
at the moment, I am having following scenario:

<telerik:RadTreeView ID="RadTreeView1" runat="server">
    <NodeTemplate>
        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Scanner5 32x32.png"
            PostBackUrl="http://www.hotmail.com" />
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.bing.com">[ View ]  </asp:HyperLink>
        <%# DataBinder.Eval(Container, "Text") %>
    </NodeTemplate>
</telerik:RadTreeView>

and the code behind looks something like below :

RadTreeNode category1 = new RadTreeNode("Group1", "Group1");
       RadTreeNode Category1Nodes;
       RadTreeNodeCollection radCollection = new RadTreeNodeCollection(category1);
       for (int i = 10 - 1; i >= 0; i--)
       {
           Category1Nodes = new RadTreeNode(i.ToString(), i.ToString());
           category1.Nodes.Add(Category1Nodes);
       }
       RadTreeView1.Nodes.Add(category1);
            
 
       RadTreeNode category2 = new RadTreeNode("Group2", "Group2");
       RadTreeNode Category2Nodes;
       radCollection = new RadTreeNodeCollection(category2);
       for (int i = 5 - 1; i >= 0; i--)
       {
           Category2Nodes = new RadTreeNode(i.ToString(), i.ToString());
           category2.Nodes.Add(Category2Nodes);
       }
       RadTreeView1.Nodes.Add(category2);


Now,

I want to set the link of the imageButon and hyperLink programatically. Right now the link target is same for all the nodes, including the parent nodes, but I want to set it dynamically.

Thanks,
-Aarsh

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Jul 2012, 05:25 AM
Hi Aarsh,

You can access the NodeTemplates dynamically and set the link as follows.

C#:
ImageButton ImageButton1 = (ImageButton)category2.FindControl("ImageButton1");
ImageButton1.PostBackUrl = "http://www.hotmail.com";
HyperLink HyperLink1 = (HyperLink)category2.FindControl("HyperLink1");
HyperLink1.NavigateUrl = "http://www.bing.com";

Hope this helps.

Regards,
Princy.
0
Aarsh
Top achievements
Rank 1
answered on 20 Jul 2012, 02:48 PM
Correct me if I am wrong but I guess, this is again going to set the link property same to all the nodes.

Can we do something described here at the end of my post ?

Thanks,
-Aarsh

Tags
TreeView
Asked by
Aarsh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Aarsh
Top achievements
Rank 1
Share this question
or