国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > XML > 正文

使用xml作為數(shù)據(jù)源,讓asp:Menu類自由擴展菜單項

2024-09-05 20:53:56
字體:
供稿:網(wǎng)友
注冊會員,創(chuàng)建你的web開發(fā)資料庫,

  先新建一個名為menu的xml文件,內(nèi)容如下:

<?xml version="1.0" encoding="utf-8" ?>
<menu>
  <menuitem url="~/default.aspx" title="首頁"  description=""/>
  <menuitem url="~/news.aspx" title="新聞"  description="">
    <menuitem url="~/news.aspx" title="國內(nèi)新聞"  description=""/>
    <menuitem url="~/news.aspx" title="國際新聞"  description=""/>
  </menuitem>
</menu>      

  然后在頁面上拖放一個menu控件,并拖放一個xmldatasource控件,id為xmldatasource1,將menu的 datasourceid設(shè)置為xmldatasource1。

  配置xmldatasource控件,使datafile="~/menu.xml" xpath="menu/menuitem",這里采用xpath來選取數(shù)據(jù),即將menuitem的數(shù)據(jù)篩選出來。

  此時,再綁定menu控件的數(shù)據(jù),告訴menu控件該怎么顯示從xml文件篩選出來的數(shù)據(jù)。選中menu控件,在屬性窗口選取databindings,在彈出的對話框里,在左上角的列表中選中menuitem,單擊添加按鈕將menuitem添加到左下的列表中,再在此列表中選擇menuitem,此是右邊的列表將顯示要綁定的屬性,使navigateurlfield="url" textfield="title"。按確定按鈕返回設(shè)計界面,此時就會顯示出"首頁"和"新聞"兩個菜單項。
  
  設(shè)計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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 水富县| 左权县| 丰台区| 获嘉县| 博乐市| 新巴尔虎右旗| 图们市| 武陟县| 新化县| 精河县| 女性| 突泉县| 蒙城县| 铅山县| 象山县| 襄樊市| 乐至县| 巴林右旗| 苍梧县| 马龙县| 灵台县| 安多县| 定结县| 麦盖提县| 三明市| 昆山市| 临漳县| 柳州市| 巨鹿县| 沈阳市| 开原市| 临安市| 靖宇县| 吴忠市| 普定县| 栾川县| 游戏| 慈溪市| 静海县| 弥渡县| 荃湾区|