DropDownList1.Items.Add(New ListItem(classname, classid))
Dim sonparentid As Integer = Integer.Parse(classid)
Dim blank As String = "├"
'递归子分类方法
BindNode(sonparentid, dt, blank)
Next
DropDownList1.DataBind()
End Sub
'绑定子分类
Private Sub BindNode(ByVal parentid As Integer, ByVal dt As DataSet, ByVal blank As String)
Dim drs As DataRow() = dt.Tables(0).Select("parentid=" & parentid)
For Each dr As DataRow In drs
Dim classid As String = dr("catalogid").ToString()
Dim classname As String = dr("catalogName").ToString()
classname = blank + classname
DropDownList1.Items.Add(New ListItem(classname, classid))
Dim sonparentid As Integer = Integer.Parse(classid)
Dim blank2 As String = blank + "─"
BindNode(sonparentid, dt, blank2)
Next
End Sub
4.3 填充树形控件
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not IsPostBack) Then
|