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

Adding Node Template Column Remove Text from Rad Tree View

5 Answers 142 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
A2H
Top achievements
Rank 1
A2H asked on 04 Jul 2012, 06:14 AM
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.

5 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 04 Jul 2012, 07:43 AM
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.
0
A2H
Top achievements
Rank 1
answered on 04 Jul 2012, 09:34 AM
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
0
A2H
Top achievements
Rank 1
answered on 04 Jul 2012, 09:40 AM
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
0
Princy
Top achievements
Rank 2
answered on 05 Jul 2012, 04:17 AM
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.
0
A2H
Top achievements
Rank 1
answered on 05 Jul 2012, 05:54 AM
Thanks Princy.

Its working fine.
Tags
TreeView
Asked by
A2H
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
A2H
Top achievements
Rank 1
Share this question
or