Setting ITemplate for DataBound Menu Items

6 posts, 0 answers
  1. Fire
    Fire avatar
    2 posts
    Member since:
    Jan 2011

    Posted 11 Jan 2011 Link to this post

    I have issues setting a custom ITemplate implementation on RadMenuItems.

    I populate the RadMenu using the DataSource property.

    In which event during the databinding am I supposed to set the ItemTemplate property on the RadMenuItem (which gets created during the databinding process ... I populate the DataSource using custom data objects) so that it gets applied?

    The second issue ... I only want to apply the custom ITemplate implementation for one level in the MenuItem hierarchy. The first level should use the default rendering, the second level should use a custom template.
  2. Yana
    Admin
    Yana avatar
    4993 posts

    Posted 14 Jan 2011 Link to this post

    Hello,

    Please check the following help articles about adding templates at run-time:

    Templates Overview
    Adding templates

    you can set the template only for child  items by checking the item level:

    TextBoxTemplate template = new TextBoxTemplate();
    foreach (RadMenuItem item in RadMenu1.GetAllItems())
     {
         if(item.Level > 0)
            template.InstantiateIn(item);
     }
    RadMenu1.DataBind();

    Hope this helps.

    Regards,
    Yana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. Fire
    Fire avatar
    2 posts
    Member since:
    Jan 2011

    Posted 18 Jan 2011 Link to this post

    I saw that sample. That is not what I want, nor is it what I was asking for.

    Which is why I asked for a sample using the DataSource Property  "I populate the RadMenu using the DataSource property."

    So again: I connect a DataSource implementatioin to the Radmenu instance using the DataSource property. How do I instantiate and assign the ITemplate implementation for the menu items?

    In which event am I supposed to set the Itemplate?
  4. Yana
    Admin
    Yana avatar
    4993 posts

    Posted 19 Jan 2011 Link to this post

    Hello,

    I've attached a simple example with Northwind database to demonstrate the approach, please download it and give it a try.

    Kind regards,
    Yana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  5. Gian Carlo Zamboni
    Gian Carlo Zamboni avatar
    29 posts
    Member since:
    Mar 2007

    Posted 10 Aug 2011 Link to this post

    The example code help me with the same problem, thanks. I think you should add to your documentation the line code "item.databind();" when using a datasource.
  6. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 15 Aug 2011 Link to this post

    Hi Gian,

    Thanks for the reasonable suggestion. We will review the documenation and make the needed improvements.

    Regards,
    Peter
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top