• 用C# + SqlServer2005 实现的treeview动态树形菜单


    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 TreeView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnTV_Click(object sender, EventArgs e)
        {
            CreateTreeView(TreeView1.Nodes, "0");
        }


        /**/
        /// <summary>
        /// 根据递归查询结果动态生成TreeView
        /// </summary>

        private DataSet CreateDataSet()
        {
            string connetion = "database=test;server=.;uid=sa;pwd=sa123456;";
            using (SqlConnection con = new SqlConnection(connetion))
            {
                SqlCommand com = new SqlCommand("select * from QuHua", con);
               
                SqlDataAdapter da = new SqlDataAdapter(com);
                DataSet ds = new  DataSet();
                da.Fill(ds,"tree");
               

                return ds;
            }

        }

        /// <summary>
        /// 递归查询
        /// </summary>
        /// <param name="nodes">TreeView的节点集合</param>
        /// <param name="parentid">所属父级的ID</param>
        private void CreateTreeView(TreeNodeCollection nodes, string parentid)
        {
            DataView TempDV = new DataView();
            TreeNode TempNode;
            //string intId;
            TempDV.Table = CreateDataSet().Tables["tree"];
            TempDV.RowFilter = "ParentID=" + parentid + "";
            foreach (DataRowView drv in TempDV)
            {
                TempNode = new TreeNode();
                TempNode.Value = drv["TreeID"].ToString();
                TempNode.Text = drv["TreeName"].ToString();
                TempNode.NavigateUrl = drv["NodeUrl"].ToString();
                nodes.Add(TempNode);

                //intId = drv["ParentID"].ToString();

                CreateTreeView(TempNode.ChildNodes, TempNode.Value);

            }

        }

    }

  • 相关阅读:
    视频、图形图像处理之Opencv技术记录(六)、均衡直方图
    视频、图形图像处理之Opencv技术记录(四)、OpenCV教程概述
    视频、图形图像处理之Opencv技术记录(五)、Opencv教程之图像处理(imgproc模块)之平滑图像
    Windows与Linux之间海量文件的传输与Linux下大小写敏感问题
    RedHat7.4 yum配置
    虚拟机网络设置(NAT模式)
    Linux虚拟机安装(rhel 7.4)
    maven安装与基本配置
    安装JDK(Windows)
    VMware虚拟机开机自启动
  • 原文地址:https://www.cnblogs.com/wills2010/p/1836459.html
Copyright © 2020-2023  润新知