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

show own node when no records available

1 Answer 56 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mario
Top achievements
Rank 1
Mario asked on 24 Jan 2012, 11:31 PM
Hello,

I fill a
treeview with a ObjectDataSource object. It may be that the ObjectDataSource object does not return a record supplies. Should this be the case, then, a node can be displayed. How can I realize something like that?

<telerik:RadTreeView ID="RadTreeView1" Runat="server" DataFieldID="LayoutID"
                  DataFieldParentID="ParentID" DataSourceID="ObjectDataSource1"
                  DataTextField="LayoutName" DataValueField="LayoutArt"
                  onnodedatabound="RadTreeView1_NodeDataBound" 
                    Width="100%" oncontextmenuitemclick="RadTreeView1_ContextMenuItemClick">


Hope you can understand me.
  • No record from DataSource - own node to be displayed
  • Records available from DataSource - no separate node


Best regards
Reiner

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 25 Jan 2012, 02:04 PM
Hello Mario,

You can use the DataBound server event and check there if the tree has any nodes. If not, than you can add one manually. Here's an example:
protected void RadTreeView1_DataBound(object sender, EventArgs e)
{
    if (RadTreeView1.Nodes.Count == 0)
    {
        RadTreeNode node = new RadTreeNode("NodeText");
        RadTreeView1.Nodes.Add(node);
    }
}

 
Regards,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
TreeView
Asked by
Mario
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or