Menu控件小用,xml,sitemap数据源.aspx
Code
<%@ Page Language="C#" %>
<script runat="server">
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
ListBox1.Items.Add(e.Item.Parent.Value + " : " + e.Item.Value);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Menu Server Control</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Menu ID="Menu2" Runat="server" DataSourceID="SiteMapDataSource1">
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" Runat="server" StartingNodeUrl="Finance.aspx" />
<hr />
<asp:Menu ID="Menu1" Runat="server" DataSourceID="XmlDataSource1" OnMenuItemClick="Menu1_MenuItemClick">
<DataBindings>
<asp:MenuItemBinding DataMember="Item" TextField="Category"></asp:MenuItemBinding>
<asp:MenuItemBinding DataMember="Option" TextField="Choice"></asp:MenuItemBinding>
</DataBindings>
</asp:Menu>
<br />
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="210px" Width="193px"></asp:ListBox>
<asp:xmldatasource ID="XmlDataSource1" runat="server" datafile="Hardware.xml" />
</form>
</body>
</html>
<%@ Page Language="C#" %>
<script runat="server">
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
ListBox1.Items.Add(e.Item.Parent.Value + " : " + e.Item.Value);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Menu Server Control</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Menu ID="Menu2" Runat="server" DataSourceID="SiteMapDataSource1">
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" Runat="server" StartingNodeUrl="Finance.aspx" />
<hr />
<asp:Menu ID="Menu1" Runat="server" DataSourceID="XmlDataSource1" OnMenuItemClick="Menu1_MenuItemClick">
<DataBindings>
<asp:MenuItemBinding DataMember="Item" TextField="Category"></asp:MenuItemBinding>
<asp:MenuItemBinding DataMember="Option" TextField="Choice"></asp:MenuItemBinding>
</DataBindings>
</asp:Menu>
<br />
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="210px" Width="193px"></asp:ListBox>
<asp:xmldatasource ID="XmlDataSource1" runat="server" datafile="Hardware.xml" />
</form>
</body>
</html>
Hardware.xm
Code
<?xml version="1.0" encoding="utf-8"?>
<Hardware>
<Item Category="Motherboards">
<Option Choice="Asus" />
<Option Choice="Abit" />
</Item>
<Item Category="Memory">
<Option Choice="128mb" />
<Option Choice="256mb" />
<Option Choice="512mb" />
</Item>
<Item Category="HardDrives">
<Option Choice="40GB" />
<Option Choice="80GB" />
<Option Choice="100GB" />
</Item>
<Item Category="Drives">
<Option Choice="CD" />
<Option Choice="DVD" />
<Option Choice="DVD Burner" />
</Item>
</Hardware>
<?xml version="1.0" encoding="utf-8"?>
<Hardware>
<Item Category="Motherboards">
<Option Choice="Asus" />
<Option Choice="Abit" />
</Item>
<Item Category="Memory">
<Option Choice="128mb" />
<Option Choice="256mb" />
<Option Choice="512mb" />
</Item>
<Item Category="HardDrives">
<Option Choice="40GB" />
<Option Choice="80GB" />
<Option Choice="100GB" />
</Item>
<Item Category="Drives">
<Option Choice="CD" />
<Option Choice="DVD" />
<Option Choice="DVD Burner" />
</Item>
</Hardware>
Web.sitemap
Code
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode title="Home" description="Home Page" url="Default.aspx">
<siteMapNode title="News" description="The Latest News" url="News.aspx">
<siteMapNode title="U.S." description="U.S. News" url="News.aspx?cat=us" />
<siteMapNode title="World" description="World News" url="News.aspx?cat=world" />
<siteMapNode title="Technology" description="Technology News" url="News.aspx?cat=tech" />
<siteMapNode title="Sports" description="Sports News" url="News.aspx?cat=sport" />
</siteMapNode>
<siteMapNode title="Finance" description="The Latest Financial Information" url="Finance.aspx">
<siteMapNode title="Quotes" description="Get the Latest Quotes" url="Quotes.aspx" />
<siteMapNode title="Markets" description="The Latest Market Information" url="Markets.aspx"/>
<siteMapNode title="U.S. Market Report" description="Looking at the U.S. Market" url="MarketsUS.aspx" />
<siteMapNode title="NYSE" description="The New York Stock Exchange" url="NYSE.aspx" />
</siteMapNode>
<siteMapNode title="Funds" description="Mutual Funds" url="Funds.aspx" />
<siteMapNode title="Weather" description="The Latest Weather" url="Weather.aspx" />
</siteMapNode>
</siteMap>
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode title="Home" description="Home Page" url="Default.aspx">
<siteMapNode title="News" description="The Latest News" url="News.aspx">
<siteMapNode title="U.S." description="U.S. News" url="News.aspx?cat=us" />
<siteMapNode title="World" description="World News" url="News.aspx?cat=world" />
<siteMapNode title="Technology" description="Technology News" url="News.aspx?cat=tech" />
<siteMapNode title="Sports" description="Sports News" url="News.aspx?cat=sport" />
</siteMapNode>
<siteMapNode title="Finance" description="The Latest Financial Information" url="Finance.aspx">
<siteMapNode title="Quotes" description="Get the Latest Quotes" url="Quotes.aspx" />
<siteMapNode title="Markets" description="The Latest Market Information" url="Markets.aspx"/>
<siteMapNode title="U.S. Market Report" description="Looking at the U.S. Market" url="MarketsUS.aspx" />
<siteMapNode title="NYSE" description="The New York Stock Exchange" url="NYSE.aspx" />
</siteMapNode>
<siteMapNode title="Funds" description="Mutual Funds" url="Funds.aspx" />
<siteMapNode title="Weather" description="The Latest Weather" url="Weather.aspx" />
</siteMapNode>
</siteMap>
l