把sitemap 的节点写成treeview的结构时候,出现错误

dpxlove 2009-01-13 04:50:03
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="掌上就业系统" description="掌上就业系统">
<siteMapNode url ="" title="信息管理" description="信息管理">
<siteMapNode url="~/RightWork/InfoCollect.aspx" title="信息采集" description="信息采集"></siteMapNode>
</siteMapNode>

<siteMapNode url="" title="帐户管理" description="帐户管理">
<siteMapNode url="~/Accounts/AddUser.aspx" title ="新建账户" description ="新建账户"></siteMapNode>
<siteMapNode url ="~/Accounts/UpdateUser.aspx" title ="修改账户" description ="修改账户"></siteMapNode>
</siteMapNode>

<siteMapNode url ="" title ="操作日志" description ="操作日志">
<siteMapNode url ="~/logs/OperationLog.aspx" title ="操作记录" description ="操作记录"></siteMapNode>
</siteMapNode>
</siteMapNode >
</siteMap>

将上面的siteMapNode写成treeview时出现错误,点击账户管理,操作日志及其子节点时,就是点击的信息管理,都弄了一天了,也没弄出来,谁来救救我吧。注:C#写了两个方法,
private void AddAllTreeNode()
{
this.TreeViewFunc .Nodes .Clear ();
string xmlpath = HttpContext.Current.Server.MapPath(Page.Request .ApplicationPath +"/Web.sitemap");
XmlDocument xml=new XmlDocument ();
xml.Load (xmlpath);
foreach (XmlNode siteMap in xml.ChildNodes)
{
if (siteMap is XmlElement && siteMap.Name == "siteMap")
{
if (siteMap.ChildNodes.Count > 0)
{
XmlNode siteMapNode_Root = siteMap.ChildNodes[0];
string title_Root = "掌上就业系统";
string url_Root = "";
if(siteMapNode_Root.Attributes ["title"].Value !=null)
title_Root = siteMapNode_Root.Attributes["title"].Value;
//if(siteMapNode_Root.Attributes ["url"].Value !=null)
url_Root = siteMapNode_Root.Attributes["url"].Value;

TreeNode tnRoot = new TreeNode();
tnRoot.Text = title_Root;
tnRoot.Value = url_Root;
tnRoot.Expanded = true;
this.TreeViewFunc.Nodes.Add(tnRoot);

//添加其他子节点
if (siteMapNode_Root is XmlElement)
{
foreach (XmlNode subNode in siteMapNode_Root.ChildNodes)
{
AddTreeViewSubNode(tnRoot, subNode);
}
}
}
}

}
}

#region AddTreeViewSubNode(TreeNode root,XmlNode siteMap) 添加treeView的子节点
private void AddTreeViewSubNode(TreeNode root,XmlNode siteMap)
{
if (siteMap is XmlElement)
{
string title = "";
string url = "";
//if (siteMap.Attributes["title"] != null && siteMap.Attributes["title"].InnerText != null)
title = siteMap.Attributes["title"].Value ;
// if (siteMap.Attributes["url"] != null && siteMap.Attributes["url"].InnerText != null)
url = siteMap.Attributes["url"].Value ;
TreeNode node = new TreeNode();
node.Text = title;
node.Value = url;
node.Expanded = false;
root.ChildNodes.Add(node);
foreach (XmlNode subMapNode in siteMap.ChildNodes)
{
AddTreeViewSubNode(node, subMapNode);
}
}
}

又什么错误啊?在线等
...全文
66 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

111,130

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧