Hi,
Understand the following sample and try yourself :thumbsup:
Private Sub PopulateMenu()
Dim ds As DataSet = GetDataSetForMenu()
Dim menu As New Menu()
For Each parentItem As DataRow In ds.Tables("Categories").Rows
Dim categoryItem As New MenuItem(DirectCast(parentItem("CategoryName"), String))
menu.Items.Add(categoryItem)
For Each childItem As DataRow In parentItem.GetChildRows("Children")
Dim childrenItem As New MenuItem(DirectCast(childItem("ProductName"), String))
categoryItem.ChildItems.Add(childrenItem)
Next
Next
Panel1.Controls.Add(menu)
Panel1.DataBind()
End Sub
Private Function GetDataSetForMenu() As DataSet
Dim myConnection As New SqlConnection(GetConnectionString())
Dim adCat As New SqlDataAdapter("SELECT * FROM Categories", myConnection)
Dim adProd As New SqlDataAdapter("SELECT * FROM Products", myConnection)
Dim ds As New DataSet()
adCat.Fill(ds, "Categories")
adProd.Fill(ds, "Products")
ds.Relations.Add("Children", ds.Tables("Categories").Columns("CategoryID"), ds.Tables("Products").Columns("CategoryID"))
Return ds
End Function
[Modified: if you're going to provide code, learn to use the pre tags...their your friend!]