先新建一個(gè)名為menu的xml文件,內(nèi)容如下:
<?xml version="1.0" encoding="utf-8" ?>
<menu>
<menuitem url="~/default.aspx" title="首頁(yè)" description=""/>
<menuitem url="~/news.aspx" title="新聞" description="">
<menuitem url="~/news.aspx" title="國(guó)內(nèi)新聞" description=""/>
<menuitem url="~/news.aspx" title="國(guó)際新聞" description=""/>
</menuitem>
</menu>
然后在頁(yè)面上拖放一個(gè)menu控件,并拖放一個(gè)xmldatasource控件,id為xmldatasource1,將menu的 datasourceid設(shè)置為xmldatasource1。
配置xmldatasource控件,使datafile="~/menu.xml" xpath="menu/menuitem",這里采用xpath來(lái)選取數(shù)據(jù),即將menuitem的數(shù)據(jù)篩選出來(lái)。
此時(shí),再綁定menu控件的數(shù)據(jù),告訴menu控件該怎么顯示從xml文件篩選出來(lái)的數(shù)據(jù)。選中menu控件,在屬性窗口選取databindings,在彈出的對(duì)話框里,在左上角的列表中選中menuitem,單擊添加按鈕將menuitem添加到左下的列表中,再在此列表中選擇menuitem,此是右邊的列表將顯示要綁定的屬性,使navigateurlfield="url" textfield="title"。按確定按鈕返回設(shè)計(jì)界面,此時(shí)就會(huì)顯示出"首頁(yè)"和"新聞"兩個(gè)菜單項(xiàng)。
設(shè)計(jì)html代碼如下:
<%@ page language="c#" autoeventwireup="true" codebehind="default.aspx.cs" inherits="coaffiliate._default" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>untitled page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:menu id="menu1" runat="server" datasourceid="xmldatasource1" orientation="horizontal" staticenabledefaultpopoutimage="false">
<databindings>
<asp:menuitembinding datamember="menuitem" navigateurlfield="url" textfield="title" />
</databindings>
</asp:menu>
<asp:xmldatasource id="xmldatasource1" runat="server" datafile="~/menu.xml" xpath="menu/menuitem"></asp:xmldatasource>
</div>
</form>
</body>
</html>
http://www.cnblogs.com/ofei/archive/2007/01/20/625745.html
新聞熱點(diǎn)
疑難解答
圖片精選