TREEVIEW 绑定XML

aspx文件:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TreeViewXML.aspx.cs" Inherits="TreeViewXML" %>



<!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>TreeView+XML实现的菜单</title>

    <script runat="server">       

</script>

</head>

<body>

    <form id="form1" runat="server">

    <asp:TreeView ID="Treeview1" Runat="server" DataSourceID="Xmldatasource1" ExpandDepth="0" LeafNodeStyle-ImageUrl="~/Images/shareddocuments.gif">

            <DataBindings>

                <asp:TreeNodeBinding DataMember="country" Text="中国" Value="中国" />

                <asp:TreeNodeBinding DataMember="Province" TextField="name" />

                <asp:TreeNodeBinding DataMember="City" TextField="name" />

                <asp:TreeNodeBinding DataMember="Town" TextField="name" />

            </DataBindings>             

    </asp:TreeView>

        <asp:XmlDataSource ID="Xmldatasource1" Runat="server" DataFile="ProvinceCity.xml">        

        </asp:XmlDataSource>

    </form>

    



</body>

</html>



 
 
XML文件:


<?xml version="1.0" encoding="utf-8" ?>





<country>



  <Province name="广东">

    <City name="广州">

      <Town name="番禺"></Town>

      <Town name="花都"></Town>

    </City>

    <City name="深圳">

      <Town name="罗湖"></Town>

      <Town name="公明"></Town>

    </City>

    <City name="东莞">

      <Town name="东城"></Town>

      <Town name="南城"></Town>

    </City>

    <City name="佛山">

      <Town name="南海"></Town>

      <Town name="三水"></Town>

    </City>

  </Province>



  <Province name="广西">

    <City name="南宁"></City>

    <City name="桂林"></City>

    <City name="柳州"></City>

    <City name="梧州"></City>

  </Province>



  <Province name="海南">

    <City name="海口"></City>

    <City name="博鳌"></City>

    <City name="三亚"></City>

  </Province>



</country>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值