born59died60 says:
but there should be no image for the main menu, only submenu items
In order to display the image for submenu items you need to set the MenuItem Text property with Image only for the ChildItems i.e. parentMenuId not equal to 0.
Private Sub PopulateMenu(dt As DataTable, parentMenuId As Integer, parentMenuItem As MenuItem)
Dim currentPage As String = Path.GetFileName(Request.Url.AbsolutePath)
For Each row As DataRow In dt.Rows
Dim menuItem As New MenuItem() With {
.Value = row("MenuId").ToString(),
.Text = row("Title").ToString(),
.NavigateUrl = row("Url").ToString(),
.Selected = row("Url").ToString().EndsWith(currentPage, StringComparison.CurrentCultureIgnoreCase)
}
If parentMenuId = 0 Then
Menu1.Items.Add(menuItem)
Dim dtChild As DataTable = Me.GetData(Integer.Parse(menuItem.Value))
PopulateMenu(dtChild, Integer.Parse(menuItem.Value), menuItem)
Else
menuItem.Text = "<a href='MenuMasterSide.master?menuid=" & row("MenuId").ToString() & "'><img src='images/orange_square.png'></a>" & " " & row("Title").ToString()
parentMenuItem.ChildItems.Add(menuItem)
End If
Next
End Sub