介绍如何利用WebService来实现对其较大量数据(XML文件格式)动态加载TreeView节点。
操作步骤如下:
1、在VS下新建网站TreeViewDemo,文件夹结构如下图:
TreeView.aspx的代码:
<%@ Page Language="C#" %><% // TreeView.aspx // Tree View AJAX Control sample page. // Copyright (c) by Matthias Hertel, http://www.mathertel.de // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx // ----- // 02.01.2006 created by Matthias Hertel // 30.09.2006 xhtml compatibility%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Tree View AJAX Control sample page</title> <link href="../mathertel.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="../ajaxcore/ajax.js"></script> <script type="text/javascript" src="../ajaxcore/GetJavaScriptProxy.aspx?service=
../S03_AJAXControls/TreeView.asmx"></script></head><body> <mh:Title ID="Title" runat="server" /> <a href="../ViewSrc.aspx" style="position: absolute; right: 10px; top: 10px">View Source</a> <hr /> <ajax:TreeView runat="server" service="proxies.TreeView.GetSubNodes"
title="Cities in the USA" /> <mh:Footer ID="foot" runat="server" /></body></html>
WebService文件TreeView.asmx的代码:
<%@ WebService Language="C#" Class="TreeView" %>// TreeView.asmx// WebService serving data for a AJAX TreeView Control.// Copyright by Matthias Hertel, http://www.mathertel.de// This work is licensed under a Creative Commons Attribution 2.0 Germany License.// See http://creativecommons.org/licenses/by/2.0/de/// ——– // 02.01.2006 created by Matthias Hertelusing System;using System.Text;using System.Web;using System.Web.Caching;using System.Web.Services;using System.Web.Services.Protocols;using System.Web.Services.Description;using System.Xml;[WebService(Namespace = TreeView.LOCALNAMESPACE, Description = "A WebService for getting hierarchical data for the AJAX Tree Control.")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]public class TreeView : System.Web. linuxComments