tree与xml
由于开发的需要,经常会用到树型菜单,在我所用的树控件中,TreeVeiw为一个最佳选择.
现说明关键代码:
1.写一个用来填充树的.xml文件,为:Menu.XML
<?xml version="1.0" encoding="utf-8"?>
<TREENODES>
<treenode Text="计算机编程">
<treenode Text="VB.net" NavigateUrl="http://www.bjpeu.edu.cn/~yanglb/aspj/" Target="main" />
<treenode Text="C#" NavigateUrl="http://www.163.com" Target="main" />
<treenode Text="js" NavigateUrl="" Target="main" />
</treenode>
<treenode Text="网页设计">
<treenode Text="Asp" NavigateUrl="http://www.bjpeu.edu.cn/~yanglb/aspj/" Target="main" />
<treenode Text="Asp。net" NavigateUrl="www" Target="main" />
<treenode Text="JSP" NavigateUrl="www" Target="main" />
</treenode>
<treenode Text="数据库">
<treenode Text="SqlServer" />
<treenode Text="Orcale" />
<treenode Text="db2" />
</treenode>
<treenode>
</treenode>
<treenode Text="eeXML">
<treenode Text="ee22" NavigateUrl="uuu" Target="main" />
</treenode>
<treenode Text="asdasd">
<treenode Text="asdasd" NavigateUrl="http://www.baidu.com" Target="main" />
</treenode>
<treenode Text="asd">
<treenode Text="asdasd" NavigateUrl="wwww,asd.com" Target="main" />
</treenode>
</TREENODES>
2.在.aspx页面中添加TreeView控件,为:
<%@ Register TagPrefix="ie" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<form id="Form1" method="post" runat="server">
<ie:TreeView runat="server" SystemImagesPath="/webctrl_client/1_0/treeimages" ID="Treeview1"
NAME="Treeview1">
<ie:TreeNode Text="Net" ImageUrl="/webctrl_client/1_0/images/root.gif" Expanded="true"
TreeNodeSrc="Stu2.xml" />
</ie:TreeView>
</form>
这样,简单的树就生成了.
但是,为了更加方便起见,我们可以通过Ado.Net来对.XML文件进行操作,示例如下:
http://www.cnblogs.com/renyu732/archive/2005/06/11/172709.html
如果在应用的过程中,还有什么问题,可参考:
http://www.cnblogs.com/renyu732/archive/2005/06/12/173215.aspx
谢谢,若还有疑问,请留言...
现说明关键代码:
1.写一个用来填充树的.xml文件,为:Menu.XML
<?xml version="1.0" encoding="utf-8"?>
<TREENODES>
<treenode Text="计算机编程">
<treenode Text="VB.net" NavigateUrl="http://www.bjpeu.edu.cn/~yanglb/aspj/" Target="main" />
<treenode Text="C#" NavigateUrl="http://www.163.com" Target="main" />
<treenode Text="js" NavigateUrl="" Target="main" />
</treenode>
<treenode Text="网页设计">
<treenode Text="Asp" NavigateUrl="http://www.bjpeu.edu.cn/~yanglb/aspj/" Target="main" />
<treenode Text="Asp。net" NavigateUrl="www" Target="main" />
<treenode Text="JSP" NavigateUrl="www" Target="main" />
</treenode>
<treenode Text="数据库">
<treenode Text="SqlServer" />
<treenode Text="Orcale" />
<treenode Text="db2" />
</treenode>
<treenode>
</treenode>
<treenode Text="eeXML">
<treenode Text="ee22" NavigateUrl="uuu" Target="main" />
</treenode>
<treenode Text="asdasd">
<treenode Text="asdasd" NavigateUrl="http://www.baidu.com" Target="main" />
</treenode>
<treenode Text="asd">
<treenode Text="asdasd" NavigateUrl="wwww,asd.com" Target="main" />
</treenode>
</TREENODES>
2.在.aspx页面中添加TreeView控件,为:
<%@ Register TagPrefix="ie" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<form id="Form1" method="post" runat="server">
<ie:TreeView runat="server" SystemImagesPath="/webctrl_client/1_0/treeimages" ID="Treeview1"
NAME="Treeview1">
<ie:TreeNode Text="Net" ImageUrl="/webctrl_client/1_0/images/root.gif" Expanded="true"
TreeNodeSrc="Stu2.xml" />
</ie:TreeView>
</form>
这样,简单的树就生成了.
但是,为了更加方便起见,我们可以通过Ado.Net来对.XML文件进行操作,示例如下:
http://www.cnblogs.com/renyu732/archive/2005/06/11/172709.html
如果在应用的过程中,还有什么问题,可参考:
http://www.cnblogs.com/renyu732/archive/2005/06/12/173215.aspx
谢谢,若还有疑问,请留言...