RadPanelBar for ASP.NET

XmlDataSource Send comments on this topic.
See Also
ASP.NET 2.0 features > Declarative data source support > XmlDataSource

Glossary Item Box

When Telerik RadPanelBar is bound to an XmlDataSource, it will create panelbar 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:
      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:

    Configure XmlDataSource
  3. Set the DataSourceID of Telerik RadPanelBar 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 RadPanelbar1_ItemDataBound(object sender, Telerik.WebControls.RadPanelbarEventArgs e)
    {
           
    //Set additional properties
           
    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 RadPanelbar1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.RadPanelbarEventArgs)
            'Set additional properties
            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