日期:2014-05-18  浏览次数:20882 次

将表中多层数据绑定到treeview
数据库表里数据大概是三层 怎么绑定到treeview里  
有没有系统详细点的方法  
最好能有个例子
谢谢诸位了

要C#的

------解决方案--------------------
/// <summary>
/// 添加树
/// </summary>
/// <param name="ParentID"></param>
/// <param name="pNode"></param>
protected void AddTree(string ParentID, TreeNode pNode)
{
string FuncCode = string.Empty;
string FuncName = string.Empty;
string FuncURL = string.Empty;
string FuncTarget = string.Empty;
string nSonCount = string.Empty;


DataView Dv = new DataView(m_Dt);
Dv.RowFilter = " SubString(FuncCode,1,Len(FuncCode)-2) = '" + ParentID + "'";

foreach (DataRowView Row in Dv)
{
FuncCode = Row["FuncCode"].ToString();
FuncName = Row["FuncName"].ToString();
FuncURL = Row["FuncURL"].ToString();// 
FuncTarget = this.m_FuncTarget;
nSonCount = Row["nSonCount"].ToString();


TreeNode Node = new TreeNode();
Node.SelectAction = TreeNodeSelectAction.Expand;
if (FuncURL.IndexOf("?") < 3) FuncURL = FuncURL + "?1=1";
FuncURL = FuncURL + "&FuncCode=" + FuncCode + "&FuncName=" + Server.UrlEncode(FuncName);
Node.Target = FuncTarget;
Node.NavigateUrl = FuncURL;

if (pNode == null)
{
Node.Text = FuncName;
TreeView1.Nodes.Add(Node);

if (int.Parse(nSonCount) > 0) AddTree(FuncCode, Node);
}
else
{
Node.Text = FuncName;
pNode.ChildNodes.Add(Node);
if (int.Parse(nSonCount) > 0) AddTree(FuncCode, Node);
}
}
Dv = null;
}