Hi Imar,
Im getting there. If you could offer any pointers for the next step I would much appreciate it.
So far I have created a menu control on default.aspx (just for testing purposes).
Most of the examples I have found for displaying Database Data in a Menu control were in C# so it has taken me a while to get this one working (in
VB.net).
My code behind is as follows:
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
PopulateMenu()
End If
End Sub
Sub PopulateMenu()
Dim dst As DataSet = GetMenuData()
For Each masterRow As DataRow In dst.Tables("ContentType").Rows()
Dim masterItem As New MenuItem(masterRow("Description").ToString())
Menu1.Items.Add(masterItem)
For Each childRow As DataRow In masterRow.GetChildRows("Children")
Dim childItem As New MenuItem(childRow("Description").ToString())
masterItem.ChildItems.Add(childItem)
Next
Next
End Sub
Function GetMenuData() As DataSet
Dim myCon As New SqlConnection
myCon = New SqlConnection()
myCon.ConnectionString = ConfigurationManager.ConnectionStrings("CMS").Conn ectionString
'Dim con As New SqlConnection(myCon)
Dim dadContentTypes As New _
SqlDataAdapter("SELECT * FROM ContentType", myCon)
Dim dadCategories As New _
SqlDataAdapter("SELECT * FROM Category", myCon)
Dim dst As New DataSet()
dadContentTypes.Fill(dst, "ContentType")
dadCategories.Fill(dst, "Category")
dst.Relations.Add("Children", _
dst.Tables("ContentType").Columns("Id"), _
dst.Tables("Category").Columns("ContentTypeId"))
Return dst
End Function
End Class
My next task is to get the menu items to link to the relevant content within the pages.
I believe I need to modify the above code to output the ID of the ContentType/Category tables so that this can be used in the hyperlink as a query parameter.
Do I need to do this in the MenuItemClick event using the MenuEventArgs to then navigate to a url like:
"~/ContentList.aspx?ContentTypeId=" & Request.QueryString.Get("ContentTypeId") & "&CategoryId=" & Eval("Id") (as per the current nav bar buttons)?
Any help would be appreciated.
Thanks
retro