RadMenu for ASP.NET

XmlDataSource Send comments on this topic.
See Also
Data Binding > XmlDataSource

Glossary Item Box

When Telerik RadMenu is bound to an XmlDataSource, it will create menu item hierarchy automatically. However, unlike SiteMapDataSource, properties such as Text and NavigateUrl will not be automatically populated.

Please, consider the following example:

  1. Add the following xml file in the App_Data folder:
    XML Copy Code
    <?xml version="1.0" encoding="utf-8" ?>
    <
    Items Text="">
     
    <Item Text="European cities" Url="" >
       
    <Item Text="Sofia" Url="http://en.wikipedia.org/wiki/Sofia" />
       
    <Item Text="Berlin" Url="http://en.wikipedia.org/wiki/Berlin" />
       
    <Item Text="Paris" Url="http://en.wikipedia.org/wiki/Paris" />
     
    </Item>
     
    <Item Text="North American cities" Url="">
       
    <Item Text="Boston" Url="http://en.wikipedia.org/wiki/Boston" />
       
    <Item Text="San Francisco" Url="http://en.wikipedia.org/wiki/San_Francisco" />
       
    <Item Text="Seattle" Url="http://en.wikipedia.org/wiki/Seattle" />
       
    <Item Text="Toronto" Url="http://en.wikipedia.org/wiki/Toronto" />
     
    </Item>
     
    <Item Text="South American cities" Url="">
       
    <Item Text="Rio de Janeiro" Url="http://en.wikipedia.org/wiki/Rio_De_Janeiro" />
       
    <Item Text="Buenos Aires" Url="http://en.wikipedia.org/wiki/Buenos_aires" />
     
    </Item>
     
    <Item Text="Asian cities" Url="">
       
    <Item Text="Tokyo" Url="http://en.wikipedia.org/wiki/Tokyo" />
       
    <Item Text="Seul" Url="http://en.wikipedia.org/wiki/Seul" />
       
    <Item Text="Beijing" Url="http://en.wikipedia.org/wiki/Beijing" />
       
    <Item Text="Tehran" Url="http://en.wikipedia.org/wiki/Teheran" />
     
    </Item>
     
    <Item Text="African cities" Url="">
       
    <Item Text="Kano" Url="http://en.wikipedia.org/wiki/Kano" />
       
    <Item Text="Johannesburg" Url="http://en.wikipedia.org/wiki/Johannesburg" />
       
    <Item Text="BeninCity" Url="http://en.wikipedia.org/wiki/Benin" />
     
    </Item>
    </
    Items>
                    
  2. Drag an instance of the XmlDataSource in the web form and configure the control:
    Configuring XmlDataSource
  3. Set the DataSourceID of Telerik RadMenu to the ID of the XmlDataSource or choose data source from the smart tag:

    Choose Data Source
  4. To map the Text, Value and NavigateUrl fields you can set the following properties to the corresponding attributes in the XML file:

      Copy Code
    DataTextField = "Text"
    DataNavigateUrlField= "Url"
    DataValueField= "Value"
                        

    The xml file for this particular example does not have a Value field, so you cannot actually populate the Value property of the items.
  5. To map additional properties or overwrite already populated properties, you can subscribe to the ItemDataBound event and use the following method:

    C# Copy Code
    protected void RadMenu1_ItemDataBound(object sender, Telerik.WebControls.RadMenuEventArgs e)
    {
       
    if (e.Item.Level > 0)//set tooltip only for child items
       {            
          
    XmlElement element = (XmlElement)e.Item.DataItem;
          e.Item.ToolTip =
    "Read more about " + element.Attributes["Text"].Value;
       }
    }        

    VB Copy Code
    Protected Sub RadMenu1_ItemDataBound(sender As Object, e As Telerik.WebControls.RadMenuEventArgs)
       If e.Item.Level > 0 Then 'set tooltip only for child items
          Dim element As XmlElement = DirectCast(e.Item.DataItem, XmlElement)
          e.Item.ToolTip = "Read more about " + element.Attributes("Text").Value
       End If
    End Sub
     

See Also