首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • treeview 的层次显示 [无满意答案结贴,结贴人:sssjjjpppsjp]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • sssjjjpppsjp
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    • 揭帖率:
    发表于:2008-05-22 17:21:13 楼主
    加了个treeview,开始是显示两层的,后来想改为四层,但是改了以后还是只能显示两层,这是怎么回事,treeview最多支持几层?

    代码发上来,希望各位高手帮我检查检查

    ASPX页面:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="left.aspx.cs" Inherits="left" %>

    <!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>无标题页 </title>
     
    </head>
    <body bgcolor="#fbf2ea" style="font-size:12px;">
        <form id="form1" runat="server">
       
            <asp:TreeView ID="trvleft" runat="server" MaxDataBindDepth="4" OnSelectedNodeChanged="trvleft_SelectedNodeChanged"
                OnTreeNodePopulate="trvleft_TreeNodePopulate" BackColor="#FBF2EA" ShowLines="True" NodeIndent="10">
                <Nodes>
                    <asp:TreeNode PopulateOnDemand="True" Text="大鲵信息库" Value="大鲵信息库"> </asp:TreeNode>
                </Nodes>
                <NodeStyle BackColor="WhiteSmoke" BorderColor="WhiteSmoke" BorderStyle="Solid" BorderWidth="1px"
                    ChildNodesPadding="2px" />
                <LeafNodeStyle NodeSpacing="2px" />
            </asp:TreeView>
         
        </form>
    </body>
    </html>


    CS页面:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;

    public partial class left : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        void PopulateCategories(TreeNode node)
        {
            SqlCommand sqlQuery = new SqlCommand("Select className,classID From daniclass where bigclassID=@bigclassid");
            sqlQuery.Parameters.Add("@bigclassid", SqlDbType.Int).Value =node.Value;
           
            DataSet resultSet= RunQuery(sqlQuery);
         
            if (resultSet.Tables.Count > 0)
            {
                foreach (DataRow row in resultSet.Tables[0].Rows)
                {
                    TreeNode NewNode = new
                        TreeNode(" <a href='classcontent.aspx?classid="+row["classID"]+"' target='right'>" + row["className"]+" </a>".ToString(),
                        row["classID"].ToString());
                    NewNode.PopulateOnDemand = true;
                    NewNode.SelectAction = TreeNodeSelectAction.Expand;
                    node.ChildNodes.Add(NewNode);
                   
                }
            }
        }

        void Populatedani(TreeNode node)
        {
            SqlCommand sqlQuery = new SqlCommand();
            sqlQuery.CommandText = "Select daniID,name From dani Where classID=@categoryid";
            sqlQuery.Parameters.Add("@categoryid", SqlDbType.Int).Value =
                node.Value;
            DataSet ResultSet = RunQuery(sqlQuery);
         
         
            if (ResultSet.Tables.Count > 0)
            {
                foreach (DataRow row in ResultSet.Tables[0].Rows)
                {

                 
                    TreeNode NewNode = new
                        TreeNode(" <a href='content.aspx?msgid=" + row["daniID"] + "' target='right'>" + row["name"].ToString() + " </a>", row["daniID"].ToString());
                    NewNode.PopulateOnDemand = false;
                    NewNode.SelectAction = TreeNodeSelectAction.None;
                    node.ChildNodes.Add(NewNode);
                 
                   
                }
            }
         
        }

        void bigclassbind(TreeNode node)
        {
            SqlCommand sqlQuery = new SqlCommand();
            sqlQuery.CommandText = "Select bigclassID,bigclassName From bigclass Where topclassID=@topclassid";
            sqlQuery.Parameters.Add("@topclassid", SqlDbType.Int).Value =node.Value;
            DataSet ResultSet = RunQuery(sqlQuery);


            if (ResultSet.Tables.Count > 0)
            {
                foreach (DataRow row in ResultSet.Tables[0].Rows)
                {


                    TreeNode NewNode = new
                        TreeNode(" <a href='mnueclass.aspx?dbname=bigclass&id=" + row["bigclassID"] + "' target='right'>" + row["bigclassName"].ToString() + " </a>", row["bigclassID"].ToString());
                    NewNode.PopulateOnDemand = true;
                    NewNode.SelectAction = TreeNodeSelectAction.Expand;
                    node.ChildNodes.Add(NewNode);


                }
            }

        }

        void topmnuebind(TreeNode node)
        {
            SqlCommand sqlQuery = new SqlCommand();
            sqlQuery.CommandText = "Select topclassID,topclassName From topclass";
            DataSet ResultSet = RunQuery(sqlQuery);


            if (ResultSet.Tables.Count > 0)
            {
                foreach (DataRow row in ResultSet.Tables[0].Rows)
                {


                    TreeNode NewNode = new
                        TreeNode(" <a href='mnueclass.aspx?dbname=topclass&id=" + row["topclassID"] + "' target='right'>" + row["topclassName"].ToString() + " </a>", row["topclassID"].ToString());
                    NewNode.PopulateOnDemand = true;
                    NewNode.SelectAction = TreeNodeSelectAction.Expand;
                    node.ChildNodes.Add(NewNode);


                }
            }

        }


        private DataSet RunQuery(SqlCommand sqlQuery)
        {

            SqlConnection DBConnection = all.createcon();
               
            SqlDataAdapter dbAdapter = new SqlDataAdapter();
            dbAdapter.SelectCommand = sqlQuery;
            sqlQuery.Connection = DBConnection;
            DataSet resultsDataSet = new DataSet();
            try
            {
                dbAdapter.Fill(resultsDataSet);
            }
            catch
            {
                Response.Write("不能连接数据库。");
            }
            return resultsDataSet;
        }


        protected void trvleft_SelectedNodeChanged(object sender, EventArgs e)
        {

        }
        protected void trvleft_TreeNodePopulate(object sender, TreeNodeEventArgs e)
        {
            if (e.Node.ChildNodes.Count == 0)
            {
                switch (e.Node.Depth)
                {
                    case 0:
                        topmnuebind(e.Node);
                        break;
                    case 1:
                        bigclassbind(e.Node);
                        break;
                    case 2:
                        Populatedani(e.Node);
                        break;
                    case 3:
                       PopulateCategories(e.Node);
                        break;
                }
            }

        }
    }

    30  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • sssjjjpppsjp
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-05-28 11:04:431楼 得分:0
    我自己顶
    问题已经解决,来的给分
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved