Unable to find the reference of a grid in treeview node

4 posts, 0 answers
  1. Subramanyam
    Subramanyam avatar
    10 posts
    Member since:
    Sep 2010

    Posted 27 Oct 2010 Link to this post

    My Design page
    <
    telerik:RadTreeView ID="tvPropertyType" runat="server" Skin="Outlook" EnableDragAndDrop="True" OnClientNodeDropping="onNodeDropping" CheckBoxes="True" CheckChildNodes="True" TriStateCheckBoxes="True" EnableDragAndDropBetweenNodes="True" DataSourceID="ObjectDataSource1" DataTextField="DocumentType" DataValueField="DocumentTypeID">
        <Nodes>
        <telerik:RadTreeNode runat="server" Text="Root RadTreeNode1">
            <Nodes>
                  <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">
                      <NodeTemplate>
                        <telerik:RadGrid ID="rgForTree" runat="server">
                      </telerik:RadGrid>
                  </NodeTemplate>
                  </telerik:RadTreeNode>
                  </Nodes>
            </telerik:RadTreeNode>
         </Nodes>
    </telerik:RadTreeView>

    My Code Behind
    Protected Sub tvPropertyType_NodeDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles tvPropertyType.NodeDataBound
     
    Dim rgForTree As RadGrid = DirectCast(e.Node.FindControl("rgForTree"), RadGrid)
            rgForTree.DataSource = Documents.GetPropertyDocumentsForUser(CInt(Me.lblPropertyID.Text), CurrentUser.UserID, e.Node.Value)
            rgForTree.DataBind()
     
        End Sub

    I am not able to get the reference for the grid.
    I have tried the code in "tvPropertyType_DataBound" as well.
    I have tried the same code in a button click which is outside the tree.

    Still not able to refer the grid in the treeview node
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Oct 2010 Link to this post

    Hello,

    Here is the code that I tried for similar scenario. Please have a look at this and find out what you are missing.

    ASPX:
    <telerik:RadTreeView ID="tvPropertyType" runat="server" Skin="Outlook" EnableDragAndDrop="True"
        AppendDataBoundItems="true" CheckBoxes="True" CheckChildNodes="True" DataSourceID="SqlDataSource2"
        TriStateCheckBoxes="True" EnableDragAndDropBetweenNodes="True" DataTextField="Text"
        DataValueField="Value" DataFieldID="id" DataFieldParentID="ParentID" OnNodeDataBound="tvPropertyType_NodeDataBound">
        <NodeTemplate>
            <telerik:RadGrid ID="rgForTree" runat="server" AllowPaging="true">
            </telerik:RadGrid>
        </NodeTemplate>
    </telerik:RadTreeView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT * FROM Tree"></asp:SqlDataSource>


    C#:
    protected void tvPropertyType_NodeDataBound(object sender, RadTreeNodeEventArgs e)
    {
        RadGrid grid = (RadGrid)e.Node.FindControl("rgForTree");
        grid.DataSource = GetDataTable("Select * from Customers where Text ='"+e.Node.Text+"'");
        grid.DataBind();     
    }




    -Shinu.
  3. Subramanyam
    Subramanyam avatar
    10 posts
    Member since:
    Sep 2010

    Posted 28 Oct 2010 Link to this post

    Hi Shinu,
    Thanks for the reply. I was able to get the Reference of the grid when i change the template i was able to get the reference of the grid. But the output is not what i wanted.
    I wanted to show a grid in the child node.
    I am able to see the child node in the grid when i use bind the grid using DataSource controls, but i dont get the reference of the grid when i change the template to show grid as a child node.

  4. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 02 Nov 2010 Link to this post

    Hi Subramanyam,

    Well you can do the following:
    1. Create the template with RadGrid in the code-behind as a class implementing the ITemplate interface (here is an article on this topic: http://www.telerik.com/help/aspnet-ajax/tree_templatesruntime.html);
    2. Handle the event TemplateNeeded (thrown for every node during binding);
    3. in the handler of TemplateNeeded check if the node should be templated with grid or not and if yes, then instantiate the template and add it to the NodeTemplate property of the node.

    This should do it!
    Hope this is helpful for you!


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top