나는 ASP.Net (VB에서)에서 다중 레벨 treeview를 생성해야하지만이 작업을 시작하는 방법에 대해서는 완전히 고민하고 있습니다. 현재 내 treeview 고정 2 레벨 접근 방식이지만 지금은 더 역동적이고 데이터베이스 테이블에 추가되는 여분의 수준을 지원하기 위해 다시 작성해야합니다.여러 수준의 ASP.NET Treeview 만들기
그래서이 트리 뷰는 새로운 레벨을 추가 할 때마다 코드를 다시 작성할 필요없이 필요한만큼의 레벨을 지원해야합니다. 이상적으로는 데이터베이스 레벨에 데이터를 삽입하는 것입니다.
는 내가 2 개 테이블 Menu
및 MenuItems
Menu
2 열 ItemID
및 ChildID
MenuItems
이 쿼리를하는 2 열 ItemID
및 Description
을 가지고있다을 만들어, 나는 데이터베이스 부품이 올바르게 설계 생각 :
SELECT
menu.Item_ID,
menu.Child_ID ,
parent.ID,
parent.Description,
child.ID,
child.Description
FROM
tblSupportTicketMenu menu
JOIN
tblSupportTicketMenuItems parent
ON
parent.ID = menu.Item_ID
JOIN
tblSupportTicketMenuItems child
ON
child.ID = menu.Child_ID
이 데이터를 반환합니다 : 여기에서
Item_ID Child_ID ID Description ID Description
----------- ----------- ----------- ---------------------------------------------------------------------------------------------------- ----------- ----------------------------------------------------------------------------------------------------
32 33 32 Level 1 33 Level 2
33 34 33 Level 2 34 Level 3
35 36 35 Item 2 Level 1 36 Item 2 Level 2
36 37 36 Item 2 Level 2 37 Item 2 Level 3
내가 갈 곳 모르는 걸, 내가 ASP를 트 리뷰는 데이터 소스로 XML 걸릴 수 있으며이 좋은 생각 일 것 같다,하지만 난 방법을 선택할 수 읽기 여러 수준 등을 지원하는 형식으로 데이터를?
누구든지이 작업을 수행하는 방법을 알고 있거나 가이드에 연결하면 매우 좋습니다. 또한 XML로 수행하는 것이 나쁜 제안 인 경우 다른 제안을 받아 들일 수 있습니다. 아직 ASP.Net을 배우고 있습니다. 나는 이것을 올바르게하고 싶다.
철저히 말하자면, 현재 교체중인 코드는 나를 위해 treeview를 생성합니다.
Dim ds As New DataTable
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Blueprint").ToString())
Dim cmd As New SqlCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "spGetMenuItemsForTickets"
cmd.Connection = conn
Using da As New SqlDataAdapter(cmd)
conn.Open()
da.Fill(ds)
conn.Close()
End Using
Dim ParentIds As List(Of Integer) = New List(Of Integer)
For Each row As DataRow In ds.Rows
If ParentIds.Contains(row("ParentID")) Then
'' Do Nothing
Else
ParentIds.Add(row("ParentID"))
End If
Next
For Each Parent As Integer In ParentIds
Dim parentNode As New System.Web.UI.WebControls.TreeNode
For Each child In ds.Rows
If (child("ParentID") = Parent) Then
Dim childNode As New System.Web.UI.WebControls.TreeNode
parentNode.Text = child("ParentDescription")
parentNode.Value = child("ParentID")
parentNode.Expanded = False
childNode.Text = child("ChildDescription")
childNode.Value = child("ChildID")
parentNode.SelectAction = TreeNodeSelectAction.None
parentNode.ChildNodes.Add(childNode)
End If
Next
trvItem.Nodes.Add(parentNode)
Next
trvItem.Nodes(0).Text += String.Empty