Wednesday, August 28, 2013

TreeView in DropDown


TreeView in DropDown


Private Sub RecursiveFillTree(ByVal dtParent As DataTable, ByVal parentID As Integer)
    level += 1
    Dim appender As StringBuilder = New System.Text.StringBuilder()
    For i = 0 To level
        appender.Append(" ")
    Next
    If level > 0 Then
        appender.Append("• ")
    End If
    Dim dv As DataView = New DataView(dtParent)
    dv.RowFilter = String.Format("ParentID = {0}", parentID)
    Dim j = 0
    If dv.Count > 0 Then
        While j < dv.Count
            ddlMTDetail.Items.Add(New ListItem(Server.HtmlDecode(appender.ToString() + dv(j)("MTDetailDesc").ToString()), dv(j)("MTDetailId").ToString()))
            RecursiveFillTree(dtParent, Convert.ToInt32(dv(j)("MTDetailId").ToString()))
            j += 1
        End While
    End If
    level -= 1
End Sub

Private Sub ShowTreeNodes()
    ddlMTDetail.Items.Clear()

    Dim sErrMsg = String.Empty
    Dim dtNodes As DataTable = objMaintenanceDb.FM_MaintenanceDetail_SelectTable()

    RecursiveFillTree(dtNodes, 0)

    ddlMTDetail.Items.Insert(0, New ListItem("- Select -", "0"))
    ddlMTDetail.SelectedIndex = 0

End Sub

No comments: