Adding Node Template Column Remove Text from Rad Tree View

6 posts, 1 answers
  1. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 04 Jul 2012 Link to this post

    Hi,

    I have a tree view control. In that I have tree view populted with Node Image and Text Property.

    I have added a new node template column with asp.Image button control inside node template column.
    But when I added node template column Text property of Rad Tree view is not showing :(.
     
    Please give some hints on this scenario.
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Jul 2012 Link to this post

    Hi A2H,

    In RadTreeView the NodeTemplate's are completely removing the default node. Thats why you are not able to see the text of the node. you should explicitly call the DataBind() method even if no datasource is set to the TreeView. Here is the sample code that I tried.

    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" runat="server">
      <Nodes>
         <telerik:RadTreeNode Text="RadTreeNode1">
         </telerik:RadTreeNode>
         <telerik:RadTreeNode Text="RadTreeNode2">
         </telerik:RadTreeNode>
         <telerik:RadTreeNode Text="RadTreeNode3">
         </telerik:RadTreeNode>
      </Nodes>
      <NodeTemplate>
         <%# DataBinder.Eval(Container, "Text") %>
         <asp:Image ID="img" runat="server" ImageUrl="~/Images/bullet5.jpg" />
      </NodeTemplate>
    </telerik:RadTreeView>

    C#:
    protected void Page_Load(object sender, EventArgs e)
        {
            RadTreeView1.DataBind();
        }

    Hope this helps.

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

    Posted 04 Jul 2012 Link to this post

    Hi Princy,

    It worked .Thanks for your Help.

    I was using databinder method.But I was not aware even if you dont have any datasource you need to call databind method.

    When I used it its working.

    Thanks,
    A2H
  5. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 04 Jul 2012 Link to this post

    Hi Princy,

    One more qs.
    I have node Template design like this
    <NodeTemplate>
         <%# DataBinder.Eval(Container, "Text") %>
         <asp:ImageButton ID="img" runat="server" ImageUrl="~/Images/bullet5.jpg" />
      </NodeTemplate>

    How can I execute differenct click event for both
    ie. For Image button click I need to execute one click event and on click of DataBinder text value I need to execute another event.

    Can you please help me on this.

    Thanks,
    A2H
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Jul 2012 Link to this post

    Hello,

    One suggestion is that you can add the text inside a Label and attach click events from the serverside as follows.

    ASPX:
    <NodeTemplate>
      <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "Text") %>'></asp:Label>
      <asp:Image ID="img" runat="server" ImageUrl="~/Images/bullet5.jpg" />
    </NodeTemplate>

    C#:
    protected void Page_Load(object sender, EventArgs e)
     {
       foreach (RadTreeNode node in RadTreeView1.Nodes)
        {
          Label Label1 = (Label)node.FindControl("Label1");
          Label1.Attributes.Add("onclick", "clickLabel();");
          Image img = (Image)node.FindControl("img");
          img.Attributes.Add("onclick", "clickImage();");
          RadTreeView1.DataBind();
        }
     }

    JS:
    <script type="text/javascript">
        function clickLabel() {
            alert("Label clicked");
        }
        function clickImage() {
            alert("Image clicked");
        }
    </script>

    Hope this helps.

    Thanks,
    Princy.
  7. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 05 Jul 2012 Link to this post

    Thanks Princy.

    Its working fine.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017