setting node's target lin k in C#

3 posts, 0 answers
  1. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 19 Jul 2012 Link to this post

    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Jul 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 20 Jul 2012 Link to this post

    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

Back to Top