Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim inttypeid As Integer = Int32.Parse(Request.QueryString("typeid"))
strsql = "select * from catalogs"
table1 = DBcon.Excuteselect(strsql)
strsql = "select catalogid,catalogname from catalogs where catalogid=" & inttypeid
dttypename = DBcon.Excuteselect(strsql)
Me.TextBox1.Text = dttypename.Rows(0)("catalogname").ToString
If dttypename.Rows.Count <> 0 Then
Me.Label1.Text = dttypename.Rows(0)("catalogname").ToString
Else
Me.Label1.Text = "此分类暂无商品"
End If
strsql = "select catalogs.*,shop.* from shop inner join catalogs on shop.catalogid=catalogs.catalogid where shop.catalogid=" & inttypeid
dttable = DBcon.Excuteselect(strsql)
dttable.Rows.Clear() '清空数据,留下表格式
For Each drrow As DataRow In table1.Rows
If drrow("catalogid") = inttypeid Then
If drrow("havechild").ToString = "y" Then '如果有子分类
Dim childtable As DataTable = table1.Clone() '克隆一个表,用来存放孩子节点
For Each row As DataRow In table1.Rows
'如果其父节点为当前节点
If row("parentid").ToString = drrow("catalogid").ToString Then
Dim newrow As DataRow = childtable.NewRow() '初始化新行
newrow.ItemArray = row.ItemArray '设置列值
childtable.Rows.Add(newrow) '填加新行
End If
Next
get_child(childtable) '递归
Else '没有子分类
strsql = "select catalogs.*,shop.* from shop inner join catalogs on shop.catalogid=catalogs.catalogid where shop.catalogid=" & inttypeid
|