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

[Solved] RadTreeViewContextMenu and DataBind

3 Answers 108 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 09 Feb 2010, 12:06 AM
Howdy,

I am trying to create my TreeView's context menu after the TreeView has been bound and do so on the server.  I am running into an issue however.  The code below results in an empty Items collection on the contextMenu object.  If I break in the code, after the DataBind(), I can see that the DataSource on the contextMenu has a collection of objects, but nothing is in the Items collection.  Therefor, there is no context menu once the page renders.

    protected void tabTreeView_OnDataBound(object sender, EventArgs e) 
    { 
        RadTreeViewContextMenu contextMenu = new RadTreeViewContextMenu(); 
 
        contextMenu.DataFieldID = "MenuItemId"
        contextMenu.DataFieldParentID = "ParentId"
        contextMenu.DataTextField = "DisplayText"
        contextMenu.DataValueField = "DisplayText"
        contextMenu.DataSource = this.GetUnusedMenuItems(); 
        contextMenu.DataBind(); 
 
        tabTreeView.ContextMenus.Add(contextMenu); 
    } 

Why is the Items collection not being populated when I call DataBind?  I can load the items in manually with a foreach loop (tested it and it works fine), but I didn't want to have to figure out the underlying hierarchy (the menu items I am using can be nested).

Thanks for any help,
Seth

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 09 Feb 2010, 01:03 PM
Hi Seth,

Can you try moving this code in Page_Load event instead? It seems to be correct.

Best wishes,
Veskoni
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Seth
Top achievements
Rank 1
answered on 10 Feb 2010, 12:18 AM
I can move it into the Page_Load event, but then my menu would not contain the correct items.  The menu is built based on the data bound within the tree.  Is there a better event to use besides OnDataBound?

Thanks
S
0
Veselin Vasilev
Telerik team
answered on 11 Feb 2010, 03:11 PM
Hello Seth,

You can try calling the DataBind() method of the treeview first and then bind the context menus.

If it does not help - please use the support ticketing system to send us a sample project which we can run locally.

Thanks

Regards,
Veskoni
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
Seth
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Seth
Top achievements
Rank 1
Share this question
or