Findcontrol inside a itemplate RadTreeviewContextMenu

5 posts, 0 answers
  1. Rubihno
    Rubihno avatar
    86 posts
    Member since:
    Jun 2008

    Posted 17 Oct 2008 Link to this post

    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..
  2. Rubihno
    Rubihno avatar
    86 posts
    Member since:
    Jun 2008

    Posted 21 Oct 2008 Link to this post

    What is the code for findcontrol into an itemtemplate?
  3. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 21 Oct 2008 Link to this post

    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.
  4. Rubihno
    Rubihno avatar
    86 posts
    Member since:
    Jun 2008

    Posted 21 Oct 2008 Link to this post

    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 
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Oct 2008 Link to this post

    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.
Back to Top