| About the demo |
 |
This demo shows how to bind ExpertMenu
to a XmlDataSource control. |
 |
All you need to do for this is to set menu's
DataSourceID property to the ID of the XmlDataSource control. |
 |
You can define a number of DataBindings
and nested PropertyBindings to map menu item properties to data members and data fields. |
 |
Here three DataBindings are defined for
three different XML elements named Book, Chapter and Section. Every DataBinding also defines
how menu item properties bind to Xml attributes.
<DataBindings>
<ec:DataBinding DataMember="Book">
<PropertyBindings>
<ec:PropertyBinding Property="Text" DataField="Title" />
</PropertyBindings>
</ec:DataBinding>
<ec:DataBinding DataMember="Chapter">
<PropertyBindings>
<ec:PropertyBinding Property="Text" DataField="Heading" />
</PropertyBindings>
</ec:DataBinding>
<ec:DataBinding DataMember="Section">
<PropertyBindings>
<ec:PropertyBinding Property="Text" DataField="Heading" />
<ec:PropertyBinding Property="PostBackOnClick" Value="True" />
</PropertyBindings>
</ec:DataBinding>
</DataBindings>
|
 |
You can define a number of PropertyBindings
to map additional item properties to other Xml attributes or assign them arbitrary values.
|
 |
You can also define a handler for
ItemDataBound server-side event for fine tuning the bound properties or
even cancel creating the item. |
<%@ Page %>
<%@ Register TagPrefix="ec" Namespace="ASPNETExpert.WebControls" Assembly="ASPNETExpert.WebControls" %>
<%@ Register TagPrefix="ecd" TagName="Header" Src="../../Controls/Header.ascx"%>
<%@ Register TagPrefix="ecd" TagName="Footer" Src="../../Controls/Footer.ascx"%>
<%@ Register TagPrefix="ecd" Namespace="ASPNETExpert.WebControls.DemoControls" Assembly="ASPNETExpert.WebControls.DemoControls" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ASP.NET Menu : ExpertMenu Demo : Bind to XmlDataSource</title>
<link href="../../style.css" type="text/css" rel="stylesheet">
</HEAD>
<body xmlns:ec="urn:http://aspnetexpert.com/ExpertControls.xsd">
<form id="Form1" method="post" runat="server">
<ecd:Header runat=server ID="Header1"></ecd:Header>
<ec:ExpertMenu runat="server" Skin="Office03Silver" id="ExpertMenu1" DataSourceID="XmlDataSource1">
<DataBindings>
<ec:DataBinding DataMember="Book">
<PropertyBindings>
<ec:PropertyBinding Property="Text" DataField="Title" />
</PropertyBindings>
</ec:DataBinding>
<ec:DataBinding DataMember="Chapter">
<PropertyBindings>
<ec:PropertyBinding Property="Text" DataField="Heading" />
</PropertyBindings>
</ec:DataBinding>
<ec:DataBinding DataMember="Section">
<PropertyBindings>
<ec:PropertyBinding Property="Text" DataField="Heading" />
<ec:PropertyBinding Property="PostBackOnClick" Value="True" />
</PropertyBindings>
</ec:DataBinding>
</DataBindings>
</ec:ExpertMenu>
<asp:XmlDataSource runat=server DataFile="../../../Tree/Data/Book.xml" ID="XmlDataSource1" />
<br>
<ecd:DescriptionView runat="server" IconUrl="../../images/kv.gif" ID="Descriptionview1">
<ecd:Description ID="Description1" runat="server">This demo shows how to bind <b>ExpertMenu</b>
to a <b>XmlDataSource</b> control.</ecd:Description>
<ecd:Description ID="Description2" runat="server">All you need to do for this is to set menu's
<b>DataSourceID</b> property to the ID of the <b>XmlDataSource</b> control.</ecd:Description>
<ecd:Description ID="Description3" runat="server">You can define a number of <b>DataBinding</b>s
and nested <b>PropertyBinding</b>s to map menu item properties to data members and data fields.</ecd:Description>
<ecd:Description ID="Description4" runat="server">Here three <b>DataBinding</b>s are defined for
three different XML elements named Book, Chapter and Section. Every DataBinding also defines
how menu item properties bind to Xml attributes.
<pre class="aspcode">
<ecd:SyntaxHighlight ID="SyntaxHighlight2" runat="server" ContentType="ASPX">
<DataBindings>
<ec:DataBinding DataMember="Book">
<PropertyBindings>
<ec:PropertyBinding Property="Text" DataField="Title" />
</PropertyBindings>
</ec:DataBinding>
<ec:DataBinding DataMember="Chapter">
<PropertyBindings>
<ec:PropertyBinding Property="Text" DataField="Heading" />
</PropertyBindings>
</ec:DataBinding>
<ec:DataBinding DataMember="Section">
<PropertyBindings>
<ec:PropertyBinding Property="Text" DataField="Heading" />
<ec:PropertyBinding Property="PostBackOnClick" Value="True" />
</PropertyBindings>
</ec:DataBinding>
</DataBindings>
</ecd:SyntaxHighlight>
</pre>
</ecd:Description>
<ecd:Description ID="Description5" runat="server">You can define a number of <b>PropertyBinding</b>s
to map additional item properties to other Xml attributes or assign them arbitrary values.
</ecd:Description>
<ecd:Description ID="Description6" runat="server">You can also define a handler for
<b>ItemDataBound</b> server-side event for fine tuning the bound properties or
even cancel creating the item.</ecd:Description>
</ecd:DescriptionView>
<ec:CodeViewTab id="CodeViewTab1" runat="server" ImagesBaseUrl="../../images/tab/">
<ec:TabItem runat="server" Text="aspx">
<pre class="aspcode">
<ecd:SyntaxHighlight runat="server" ContentType="ASPX" OutputFile="default.aspx" />
</pre>
</ec:TabItem>
<ec:TabItem runat="server" Text="Book.xml">
<pre class="aspcode">
<ecd:SyntaxHighlight ID="SyntaxHighlight1" runat="server" ContentType="XML" OutputFile="../../../Tree/Data/Book.xml" />
</pre>
</ec:TabItem>
</ec:CodeViewTab>
<ecd:Footer runat=server ID="Footer1"></ecd:Footer>
</form>
</body>
</HTML>
<?xml version="1.0" encoding="utf-8" ?>
<Book Title="Book Title">
<Chapter Heading="Chapter 1">
<Section Heading="Section 1">
</Section>
<Section Heading="Section 2">
</Section>
</Chapter>
<Chapter Heading="Chapter 2">
<Section Heading="Section 1">
</Section>
</Chapter>
</Book>