国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 开化县| 阜康市| 永州市| 崇左市| 博客| 承德市| 卓尼县| 凌云县| 崇明县| 桐城市| 盐亭县| 开鲁县| 淮安市| 乐陵市| 吉安县| 交城县| 壤塘县| 颍上县| 阿克| 临高县| 孟连| 卓资县| 江津市| 葫芦岛市| 托里县| 南澳县| 华亭县| 安远县| 时尚| 靖江市| 应用必备| 朝阳区| 长武县| 泸西县| 炉霍县| 萝北县| 敦煌市| 高平市| 苏州市| 东平县| 宁津县|