参考 http://blog.csdn.net/hgknight/archive/2004/06/13/13677.aspx//cs private void Page_Load(object sender, System.EventArgs e) { TreeView1.Attributes.Add("onclick","tree_onclick(this)"); }//js function tree_onclick(tree) { var node=tree.getTreeNode(tree.clickedNodeIndex); var ChildNode=new Array(); ChildNode=node.getChildren(); var len=parseInt(ChildNode.length) }
f exists (select * from dbo.sysobjects where id = object_id(N'[tb]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [tb] GO--示例数据 create table [tb]([id] int identity(1,1),[pid] int,name varchar(20)) insert [tb] select 0,'中国' union all select 0,'美国' union all select 0,'加拿大' union all select 1,'北京' union all select 1,'上海' union all select 1,'江苏' union all select 6,'苏州' union all select 7,'常熟' union all select 6,'南京' union all select 6,'无锡' union all select 2,'纽约' union all select 2,'旧金山'--1.得到指定id的子id列表 create function f_getchildid(@id int) returns @re table(id int) as begin insert into @re select id from tb where pid=@id while @@rowcount>0 insert into @re select a.id from tb a inner join @re b on a.pid=b.id where a.id not in(select id from @re) return end
http://blog.csdn.net/hgknight/archive/2004/06/13/13677.aspx//cs
private void Page_Load(object sender, System.EventArgs e)
{
TreeView1.Attributes.Add("onclick","tree_onclick(this)");
}//js
function tree_onclick(tree)
{
var node=tree.getTreeNode(tree.clickedNodeIndex);
var ChildNode=new Array();
ChildNode=node.getChildren();
var len=parseInt(ChildNode.length)
}
drop table [tb]
GO--示例数据
create table [tb]([id] int identity(1,1),[pid] int,name varchar(20))
insert [tb] select 0,'中国'
union all select 0,'美国'
union all select 0,'加拿大'
union all select 1,'北京'
union all select 1,'上海'
union all select 1,'江苏'
union all select 6,'苏州'
union all select 7,'常熟'
union all select 6,'南京'
union all select 6,'无锡'
union all select 2,'纽约'
union all select 2,'旧金山'--1.得到指定id的子id列表
create function f_getchildid(@id int)
returns @re table(id int)
as
begin
insert into @re select id from tb where pid=@id
while @@rowcount>0
insert into @re select a.id
from tb a inner join @re b on a.pid=b.id
where a.id not in(select id from @re)
return
end