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 clsTreeViewName;
public partial class TreeNode读取数据库_TreeContral : System.Web.UI.UserControl
{
DataView dv = new DataView();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindTreeView();
TreeView1.ExpandDepth = 0;
Response.Write("fffffffff");
TreeView1.CollapseAll();
}
}
void BindTreeView()
{
string sql = "select * from DropDownList";
clsTreeViewName.clsTreeView ctv = new clsTreeView();
dv = ctv.selectDs(sql).Tables[0].DefaultView;
foreach (DataRowView i in dv)
{
if (i["fatherId"].ToString() == "0")
{
TreeNode tn = new TreeNode();
tn.Text = i["stateName"].ToString();
tn.Value = i["stateId"].ToString();
tn.NavigateUrl = i["url"].ToString();
TreeView1.Nodes.Add(tn);
CreateChildNode(tn);
}
}
}
void CreateChildNode(TreeNode t)
{
foreach (DataRowView i in dv)
{
if (i["fatherId"].ToString() == t.Value.ToString())
{
TreeNode tn2 = new TreeNode();
tn2.Text = i["stateName"].ToString();
tn2.Value = i["stateId"].ToString();
tn2.NavigateUrl = i["url"].ToString();
t.ChildNodes.Add(tn2);
CreateChildNode(tn2);
TreeView1.ShowLines = true;
}
}
}