欢迎光临
我们一直在努力

解决了,通过DataSet的递归操作TreeView生成树状图-.NET教程,Windows开发

建站超值云服务器,限时71元/月

从csdn上问来的,谢谢stdao(道可道) 老弟,呵呵。

using microsoft.web.ui.webcontrols;
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 system.data.sqlclient;
namespace test
{
public class webform1 : system.web.ui.page
{
protected microsoft.web.ui.webcontrols.treeview tv;

private void page_load(object sender, system.eventargs e)
{
if (!page.ispostback)
{bindtree(tv.nodes,"0");}
}
private void bindtree(treenodecollection nds , string depid)
{
dataset ds=bindds();//获取dataset,具体代码略
dataview dv=ds.tables["tree"].defaultview;
dv.rowfilter="hidepid="+depid;
treenode tn;
string strid;
foreach(datarowview dr in dv)
{
  strid=dr["depid"].tostring();
  if (strid!="")
  {
   tn=new treenode();
   tn.id=dr["depid"].tostring();
   tn.text=dr["name"].tostring();
   nds.add(tn);
   bindtree(nds[nds.count-1].nodes,strid);
  }
}
}
}
}

数据库结构:
create table [dbo].[tbdep] (
    [depid] [smallint] identity (1, 1) not null ,
    [depname] [varchar] (50) not null ,
    [hidepid] [smallint] null ,
)

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 解决了,通过DataSet的递归操作TreeView生成树状图-.NET教程,Windows开发
分享到: 更多 (0)