RadMenu for ASP.NET
Search RadMenu for ASP.NET
Contents
At a glance
How RadMenu compares to ASP.NET Menu
How RadMenu compares to ASP.NET menu
What's new
Licensing
Installation and deployment
DNN
Feature overview
Getting Started
New to Telerik RadMenu?
Already using the control
AJAX support
Templates
Context Menu
Custom Attributes
ASP.NET 2.0 features
Defining the Telerik RadMenu structure
Data Binding
Overview and types of data sources
DataTable, DataSet or DataView
Access database and OleDbDataAdapter
SQL database and SqlDataAdapter
SqlDataSource or AccessDataSource
SiteMapDataSource
XmlDataSource
ObjectDataSource
ArrayList
Append databound items
Controlling the visual appearance
Example scenarios (How to)
Telerik RadMenu client-side
Telerik RadMenu server-side
Troubleshooting
API Reference
Get more help
PID412 ; RID7VID0
XmlDataSource
Send comments
on this topic.
See Also
Language Filter: All
Language Filter: Multiple
Language Filter: Visual Basic .NET
Language Filter: C#
Data Binding > XmlDataSource
Visual Basic .NET
C#
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:
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
>
Drag an instance of the XmlDataSource in the web form and configure the control:
Set the
DataSourceID
of Telerik RadMenu to the ID of the XmlDataSource or choose data source from the smart tag:
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.
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
Code library project on Data Binding
Declarative Data Sources online example
SiteMapDataSource
SqlDataSource or AccessDataSource