Access a treeview inside a PanelBar

3 posts, 0 answers
  1. sudesh
    sudesh avatar
    7 posts
    Member since:
    Feb 2009

    Posted 21 Apr 2009 Link to this post

    Hello,

    There is a treeview control added as a item inside a PanelBar. I tried to add a tree node to the treeview by calling "RadTreeView1.Nodes.add(node)". It is not possible to directly access the RadTreeView inside the page load.

    Below code was tried but still it gives a runtime error.
                    RadTreeView treeViewControl = (RadTreeView)Page.FindControl("RadTreeView1");
                    treeViewControl.Nodes.Add(node);

    Could you please let me know how i can add a node to the treeView in the page load method.

    Thank you,
    Sudesh
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Apr 2009 Link to this post

    Hi Sudesh,

    I guess you have added RadTreeView as ItemTemplate of RadPanelItem and want to access the TreeView in PageLoad event. If so give a try with following code and see whether it is working as expected.

    ASPX:
     
    <telerik:radpanelbar id="RadPanelBar1" runat="server"
    <Items> 
      <telerik:RadPanelItem runat="server" Text="Root RadPanelItem1"
         <ItemTemplate> 
         <telerik:RadTreeView ID="RadTreeView1" runat="server"
         <Nodes> 
             <telerik:RadTreeNode Text="Node1"></telerik:RadTreeNode> 
         </Nodes> 
         </telerik:RadTreeView> 
         </ItemTemplate> 
      </telerik:RadPanelItem> 
      <telerik:RadPanelItem runat="server" Text="Root RadPanelItem2"></telerik:RadPanelItem> 
      <telerik:RadPanelItem runat="server" Text="Root RadPanelItem3"></telerik:RadPanelItem> 
    </Items> 
    </telerik:radpanelbar> 

    CS:
     
    protected void Page_Load(object sender, EventArgs e) 
        RadPanelItem PanelItem = (RadPanelItem) RadPanelBar1.FindItemByText("Root RadPanelItem1");  //Get the Panel Item       
        RadTreeNode node = new RadTreeNode("New Node");         //Create new node 
        RadTreeView treeViewControl = (RadTreeView)PanelItem.FindControl("RadTreeView1"); //Get reference to TreeView 
        treeViewControl.Nodes.Add(node);                        //Add node to TreeView 

    Thanks,
    Shinu.
  3. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 21 Apr 2009 Link to this post

    Hi Sudesh,

    The FindControl method provides you with a reference to any control inside any of the templates used in the RadPanelBar or any of its PanelItems. You have to make sure that you properly typecast the returned value as FindControl returns a reference to a Control class. For details on the matter please take a look at this example.

    Greetings,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top