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

can not get control's text in RadTreeView's NodeTemplate

3 Answers 131 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
PeiQi
Top achievements
Rank 1
PeiQi asked on 09 Jul 2008, 06:51 AM
Hi,

I bind a hierachical datasource onto radtreeview. 
A NodeTemplate which consists a Label is defined in the treeview.
It looks fine. All the data are displayed hierachically.

However, in the code-behind i only can get the label's text value of the first level in the hierachically. For the deeper level's  node, its label text is empty.

Any one can help?

Thank you
Geoffrey

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 09 Jul 2008, 08:10 AM
Hi PeiQi,

Does the label text of child items render in your page? Also what code are you using in order to get the label text of child items?

Providing more details about your scenario would help us get back with the proper solution.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
PeiQi
Top achievements
Rank 1
answered on 10 Jul 2008, 01:35 AM
Hi, Albert

The label is rendered properly on page.
I tried out that it is caused by adding HtmlGenericControl dynamically in NodeDataBound event.

Here is the page code:
<telerik:RadTreeView ID="treStudyArea" runat="server" Height="500px" Width="400px" EnableViewState="true"  OnNodeDataBound="databound">  
              
            <NodeTemplate> 
                 <asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Status") %>'></asp:Label> 
                 
            </NodeTemplate> 
              
        </telerik:RadTreeView> 
              
          
        <asp:HiddenField ID="hdnStudyAreaID" runat="server" Value="" /> 
          
          
        <asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">  
            <ContentTemplate> 
                <asp:Label ID="Label2" runat="server" Text="ll"></asp:Label> 
            </ContentTemplate>          
        </asp:UpdatePanel> 
          
          
        <asp:Button ID="Button1" runat="server" Text="Test" OnClick="btn_serverclick" /> 


Here is the NodeDataBound code:
protected void databound(object sender, RadTreeNodeEventArgs e)  
    {  
        RadTreeNode node = e.Node;  
 
        DataRowView dataItem = node.DataItem as DataRowView;  
 
        HtmlGenericControl rdButton = new HtmlGenericControl("input");  
 
        rdButton.Attributes.Add("type", "radio");  
        rdButton.Attributes.Add("name", "studyAreaGroup");  
        rdButton.Attributes.Add("value", dataItem["Id"].ToString());  
        rdButton.Attributes.Add("saType", dataItem["Type"].ToString());  
 
        rdButton.InnerHtml = dataItem["Name"].ToString();  
 
        rdButton.ID = "rdButton";  
          
        //rdButton.EnableViewState = true;  
 
        node.Controls.Add(rdButton);  
 
        node.Value = dataItem["Id"].ToString();  
 
        if (dataItem["Status"].ToString().Equals("I"))  
        {  
            node.ToolTip = "Inactive";  
            node.Style.Add("color", "#D3D3D3");  
        }  
        node.EnableViewState = true;  
 
    } 


Here is the Button click code:
 
    protected void btn_serverclick(object sender, EventArgs arg)  
    {  
        RadTreeNode node1 = this.treStudyArea.SelectedNode;  
 
        this.Label2.Text = (node1.Controls[1] as Label).Text;  
 
        this.up.Update();  
    } 


Thank you
PeiQi Ge
0
Atanas Korchev
Telerik team
answered on 10 Jul 2008, 07:52 AM
Hi PeiQi,

Please try using FindControl to get the label:

    protected void btn_serverclick(object sender, EventArgs arg)
    {
        RadTreeNode node1 = this.treStudyArea.SelectedNode;

        this.Label2.Text = ((Label)node1.FindControl("Label1")).Text;
    }
Greetings,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
PeiQi
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
PeiQi
Top achievements
Rank 1
Share this question
or