日期:2014-05-17 浏览次数:20923 次
TreeView view = new TreeView();
......//
DataTable dt= GetTable(sql)
Hashtable parentAndSubs = new Hashtable();
for(int i=0;i<dt.Rows.Count;i++)
{
if(parentAndSubs.ContainKeys(dt.rows[i]["大类名称"].ToStrig()) == false)
{
string parentName = dt.rows[i]["大类名称"].ToStrig();
parentAndSubs[parentName] = null;
TreeNode node=new TreeNode();
node.Name =node.Text=parentName;
DataRow[] rows=dt.Select("大类名称='"+parentName+“’”);
foreach(row IN ROWS)
{
TreeNode subNode=new TreeNode();
subNode.Text=subNode.Name=row["小类名称"].ToString();
node.Nodes.Add(subNode);
}
view.Nodes.Add(node);
}
}