相思资源网 Design By www.200059.com

刚我在做Tree view 绑定时自己摸索了一下,网上有人说TreeView绑定数据源,用什么递归绑定啥的,我不想看了,就自己试着写了一个
我是这样做的,如果有什么问题请大神指导,我是菜鸟额..
1:页面TreeView 叫tvFunction
2:新建 adminFunction.xml
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<functions>
  <function name="商品发布" url="~/page/leaves/leave.aspx">
    <subfunction name="添加商品" url="~/page/leaves/leave.aspx">
    </subfunction>
    <subfunction name="添加商品" url="~/page/leaves/leave.aspx">
    </subfunction>
  </function>
  <function name="留言发布" url="~/page/leaves/leave.aspx">
    <subfunction name="添加留言" url="~/page/leaves/leave.aspx">
    </subfunction>
    <subfunction name="修改留言" url="~/page/leaves/leave.aspx">
    </subfunction>
  </function>
</functions>

3:页面绑定
复制代码 代码如下:
/// <summary>
        /// 初始化功能树结构
        /// </summary>
        private void InitFunction()
        {
            XmlDocument xmldoc = new XmlDocument();
            string xmlPath = "~/adminFunction.xml";
            xmlPath = Server.MapPath(xmlPath);
            xmldoc.Load(xmlPath);
            XmlNode root = xmldoc.DocumentElement;

            foreach (XmlNode node in root.ChildNodes)
            {
                //获取父节点的信息显示(轻狂-书生)
                XmlElement x1 = node as XmlElement;
                string name = x1.GetAttribute("name");
                string url = x1.GetAttribute("url");
                TreeNode tn = new TreeNode();
                tn.Text = name;
                tn.NavigateUrl = url;
                foreach (XmlNode subnode in x1.ChildNodes)
                {
                    XmlElement subxmlEmt = subnode as XmlElement;
                    string subname = subxmlEmt.GetAttribute("name");
                    string suburl = subxmlEmt.GetAttribute("url");
                    TreeNode subtn = new TreeNode();
                    subtn.Text = subname;
                    subtn.NavigateUrl = suburl;
                    tn.ChildNodes.Add(subtn);


                }
                tvFunction.Nodes.Add(tn);

            }
        }

4:显示效果
asp.net TreeView与XML三步生成列表树

标签:
asp.net,TreeView,XML,列表树

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“asp.net TreeView与XML三步生成列表树”

暂无asp.net TreeView与XML三步生成列表树的评论...