Question Navigation Menu Question

irtony

New member
Joined
Feb 20, 2014
Messages
1
Programming Experience
Beginner
I have this database driven menu for a client, I don't remember why I set it up like this, but now they want a change that I can't seem to implement. Here's the code:
    Sub PopulateMenu()
        Dim dst As System.Data.DataSet = GetMenuData()
        For Each masterRow As System.Data.DataRow In dst.Tables("Menu_12").Rows
            Dim masterItem As New MenuItem(CType(masterRow("CategoryName"), String), "", "", "~/content_12.aspx?ID=" + CType(masterRow("CategoryID"), String), "_parent")
            NavigationMenu.Items.Add(masterItem)

            Dim subCatRows() As System.Data.DataRow = masterRow.GetChildRows("Children")
            For Each row As System.Data.DataRow In subCatRows
                Dim subCatName As String = CType(row("SubCatName"), String)
                Dim childItem As New MenuItem(subCatName, "", "", "~/content_12.aspx?CatID=" + CType(row("CategoryID"), String) + "&SubCatID=" + CType(row("SubCatID"), String), "_parent")
                masterItem.ChildItems.Add(childItem)
            Next
        Next
End Sub
Here's the problem. They want just one of the items to go to a website, not to a page on their site. How do I make it so that one item does that? I hope that makes sense. Any help is much appreciated.
Tony
 
Last edited by a moderator:
Are you saying that you want to add an extra item with different navigation rules or that you want to change the navigation rule for one of the existing items? If it's the latter, what identifies that one item?

By the way, if you're going perform string concatenation then use the concatenation operator (&) rather than the addition operator (+). Also, Rather than using CType when you want to cast/convert to an inbuilt type, use the shorter version, e.g. CStr, CInt, CBool, etc. 'CStr(masterRow("CategoryName"))' is easier to read than 'CType(masterRow("CategoryName"), String)', especially if it's used a lot. Finally, you ought to acquaint your self with the String.Format method. This:
"~/content_12.aspx?CatID=" + CType(row("CategoryID"), String) + "&SubCatID=" + CType(row("SubCatID"), String)
could be written like this:
String.Format("~/content_12.aspx?CatID={0}&SubCatID={1}", row("CategoryID"), row("SubCatID"))
which is much more readable.
 
Back
Top