绑定树形结构的下拉框

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)直接调用函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值