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

[Solved] How to know if a menu Item has child items?

3 Answers 269 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Sergio Cortez
Top achievements
Rank 2
Sergio Cortez asked on 02 Apr 2009, 08:00 PM
Hello everyone!
I need a little help, this might be something easy but i haven't had the solution.

Right now i'm binding a sitemap provider to the RadMenu .
At runtime i want to stablish the ImageUrl property to each MenuItem. so im using the  OnItemDatabound event like this:

  protected void RadPanel_OnItemDatabound(object sender, RadPanelBarEventArgs e)
    {
         if (e.Item.Items.Count >0)
        {
            e.Item.ImageUrl = "arrow-right.gif";
            e.Item.ExpandedImageUrl = "arrow-down.gif";
            e.Item.ImagePosition = RadPanelItemImagePosition.Right;
        }
    }
 but i want only to use the image url only to Items that has children.
I can't see how to make this validation.   I hoped to be a Property called HasChildren() or something :(
I tried to use the  Item.Items.Count  but it doesnt work.
I appreciate any help
Thank you


3 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 03 Apr 2009, 09:32 AM
Hello Sergio Cortez,

This is the correct way to check if a menu has child items. However it does not work during databinding because the menu is bound from top to bottom. This means that the item really does not have any children because they are not bound yet. I suggest you traverse all items after databinding (subscribe to the DataBound event of your menu) and execute that same code there.

Kind regards,
Albert
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Sergio Cortez
Top achievements
Rank 2
answered on 03 Apr 2009, 08:23 PM
Ok Thank you Albert
This works great!
And it makes a lot of sense.
BTW, I want ot make use of this post  to ask  another question
is  there a way to now if an Item has a parent Item?
Something like    RadMenuItem.HasParent()
:p
Thank you very much





0
Accepted
Veselin Vasilev
Telerik team
answered on 06 Apr 2009, 01:44 PM
Hello Sergio Cortez,

You can use the Owner property of the menu item.

Kind regards,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Menu
Asked by
Sergio Cortez
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Sergio Cortez
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Share this question
or