using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace conTreeTest
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection Conn;
protected Microsoft.Web.UI.WebControls.TreeView tvMeau;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Microsoft.Web.UI.WebControls.TreeNode rootnode = new Microsoft.Web.UI.WebControls.TreeNode();
rootnode.Expanded = true;
tvMeau.Nodes.Add(rootnode);
CreateTree(rootnode,0);
}
//从根节点开始递归调用显示子树
public void CreateTree(Microsoft.Web.UI.WebControls.TreeNode Nds,int galleryId)
{
SqlDataAdapter myCmd=new SqlDataAdapter( "select * from Folders ",Conn);
Conn.Open();
DataSet ds=new DataSet();
myCmd.Fill(ds, "Folders ");
DataView dv=new DataView();
dv.Table=ds.Tables[ "Folders "];
dv.RowFilter= "GalleryId= 'galleryId ' ";
foreach(DataRowView drv in dv)
{
Nds.Text = drv[ "ChartName "].ToString().Trim();
Nds.Expanded = true;
Nds.Nodes.Add(Nds);
int id = int.Parse(drv[ "GalleryId "].ToString().Trim());
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Conn = new System.Data.SqlClient.SqlConnection();
//
// Conn
//
this.Conn.ConnectionString = "workstation id=LH;packet size=4096;integrated security=SSPI;data source=\ ".\ ";persi " +
"st security info=False;initial catalog=edoorvision ";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
数据库连接和TreeView是拉的控件 ,控件没问题。
表 Folders
ChardId GalleryId ChartName 以下是几个值
01 0 图库1
0101 01 图档1
0102 01 图档2