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

Unable to find the reference of a grid in treeview node

3 Answers 44 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Subramanyam
Top achievements
Rank 1
Subramanyam asked on 27 Oct 2010, 02:19 PM
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

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Oct 2010, 07:02 AM
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.
0
Subramanyam
Top achievements
Rank 1
answered on 28 Oct 2010, 09:50 AM
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.

0
Nikolay Tsenkov
Telerik team
answered on 02 Nov 2010, 02:26 PM
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
Tags
TreeView
Asked by
Subramanyam
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Subramanyam
Top achievements
Rank 1
Nikolay Tsenkov
Telerik team
Share this question
or