绑定树形结构的下拉框

1.函数

#Region "下拉框树形绑定"
    Private Function DDLBind(ByVal ddl As DropDownList, ByVal dt As DataTable)
        Dim fatherid As String
        If dt.Rows.Count = 0 Then Exit Function
        Dim i As Integer = dt.Rows.Count - 1
        Me.TextBox1.Text = Me.TextBox1.Text + 1
        Dim n As Integer = Me.TextBox1.Text
        Dim j As Integer
        While i + 1 > 0
            If IsDBNull(dt.Rows(i).Item("DC_PARENT_ID")) Then
                fatherid = ""
            Else
                fatherid = dt.Rows(i).Item("DC_PARENT_ID")
            End If

            Dim strPading As String = ""

            If ddl.Items(n).Value = fatherid Then
                For j = 0 To n
                    strPading += " "
                Next

                Dim rslist As New ListItem
                rslist.Text = strPading & "├" & dt.Rows(i).Item("DC_NAME")
                rslist.Value = dt.Rows(i).Item("DC_ID")
                ddl.Items.Add(rslist)

                dt.Rows(i).Delete()
                dt.AcceptChanges()

                DDLBind(ddl, dt)

                i = dt.Rows.Count
            End If
            i = i - 1
        End While
    End Function
#End Region

2.应用

1)在页面放置一textbox控件,id=”textbox1”,text=-1

2)直接调用函数

你可能感兴趣的:(integer,textbox,function,string)