110,536
社区成员
发帖
与我相关
我的任务
分享
select parent,citys=
rtrim(stuff((select city+' ' from tst t where t.parent=tst.parent for xml path('')),1,0,''))
from tst
group by parent
private void InitEx()
{
db d = new db();
SqlDataReader dr = d.GetAll();
while (dr.Read())
{
TreeNode tnp = new TreeNode(dr["parent"].ToString());
string[] sCitys = dr["citys"].ToString().Split(' ');
foreach (string sCity in sCitys)
{
TreeNode tnc = new TreeNode(sCity);
tnp.Nodes.Add(tnc);
}
treeView1.Nodes.Add(tnp);
}
dr.Close();
}
Protected Sub BindTreeView(byval Tv As TreeView)
Dim dt as DataTable
dt = GetDt("select * from tablename where parentid = 0order by sortid")
for i as integer = 0 to dt.rows.count -1
dim tn as new treenode
'绑定tn的各个属性
tv.nodes.add(tn)
if dt.rows(i)("myhref").tostring.length = 0 then
bindchildnode(tn,convert.toint32(dt.rows(i)("id")))
end if
next
end sub
protected sub bindchildnode(byval tn as treenode,byval pid as integer)
dim dt as datatable
dt = GetDt("select * from tablename where parentid = '"+pid.tostring+"' order by sortid")
for i as integer = 0 to dt.rows.count -1
dim treeN as new treenode
'各种绑定
tn.childnodes.add(treeN)
if dt.rows(i)("myhref").tostring.length = 0 then
bindchildnode(treen,convert.toint32(dt.rows(i)("id")))
end if
next
end sub