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

Findcontrol inside a itemplate RadTreeviewContextMenu

4 Answers 69 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rubihno
Top achievements
Rank 1
Rubihno asked on 17 Oct 2008, 02:05 PM
Hi,

I have a treeview with Radcontextmenu, and itemplate contains other control..., when i make button_click that is a button into a itemplate.., i can't accessing control into itemplate..for example for set visible = false the controls that are inside the itemplate..

4 Answers, 1 is accepted

Sort by
0
Rubihno
Top achievements
Rank 1
answered on 21 Oct 2008, 06:39 AM
What is the code for findcontrol into an itemtemplate?
0
Veselin Vasilev
Telerik team
answered on 21 Oct 2008, 07:03 AM
Hi Rubihno,

You need to find the node and then search withing the Controls collection of the node:

RadTreeNode node = RadTreeView1.FindNodeByText("My Node"); 
Button btn = (Button)node.FindControl("Button1"); 
btn.Text = "My new button text"

I hope this helps.

All the best,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rubihno
Top achievements
Rank 1
answered on 21 Oct 2008, 10:24 AM
I tried but it does not work

I post my code:

    <telerik:RadTreeView ID="RdTreeView" runat="server" Skin="Sunset"  
            Enabled="true" AllowNodeEditing="false" ExpandAnimation-Type="InElastic"  
            EnableDragAndDrop="True" EnableDragAndDropBetweenNodes="True"   
            MultipleSelect="True" SingleExpandPath="true" ShowLineImages="true" > 
         <ContextMenus> 
       <telerik:RadTreeViewContextMenu runat="server" ID="HelpDeskMenu" ClickToOpen="True" Skin="Vista"
           <Items> 
           <telerik:RadMenuItem  Text="New"  Visible="true"
         <ItemTemplate> 
 
         <asp:button ID="test1" runat="server" OnClick="test1_Click"/> 
         <asp:Button ID="test2" runat="server" /> 
         
         </ItemTemplate> 
           </telerik:RadMenuItem> 
           </Items>                       
       </telerik:RadTreeViewContextMenu> 
   </ContextMenus> 
  <CollapseAnimation Type="OutQuint" Duration="100"></CollapseAnimation> 
 
<ExpandAnimation Duration="100"></ExpandAnimation> 
         
        </telerik:RadTreeView> 
       
In itemtemplate i have 2 button, when i click on button("test1" )would you like set visible = false the button ("test2"), for make this i must to findcontrol into an itemtemplate in event test1_Click

Protected Sub test1_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
 
 
       'code 
 
 
    End Sub 
0
Shinu
Top achievements
Rank 2
answered on 22 Oct 2008, 07:31 AM
Hi Rubihno,

Try the following code snippet to achieve the desired scenario.

VB:
 
 
     Protected Sub test1_Click(sender As Object, e As EventArgs) 
         Dim btnTest1 As Button = DirectCast(sender, Button) 
         Dim menuitem As RadMenuItem = DirectCast(btnTest1.NamingContainer, RadMenuItem) 
         Dim btnTest2 As Button = DirectCast(menuitem.FindControl("test2"), Button) 
         btnTest2.Visible = False 
     End Sub 
 
 

Regards
Shinu.
Tags
TreeView
Asked by
Rubihno
Top achievements
Rank 1
Answers by
Rubihno
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Shinu
Top achievements
Rank 2
Share this question
or