
Navigator : Home > Tutorials > Controls Tutorials > ...
SQL Database Driven Menu in ASP.Net (VB.NET)
This tutorial will show you how to bind a Menu Control to SQL Server database using VB.NET. By using this sample, you can create a database driven menu in ASP.Net.
Create a method of GetMenuData to read data of menu from database to dataset
Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.
Function GetMenuData() As DataSet
Dim con As New SqlConnection(connectionString) Dim dadCats As New _ SqlDataAdapter("SELECT * FROM Categories", con) Dim dadProducts As New _ SqlDataAdapter("SELECT * FROM Products", con) Dim dst As New DataSet() dadCats.Fill(dst, "Categories") dadProducts.Fill(dst, "Products") dst.Relations.Add("Children", _ dst.Tables("Categories").Columns("CategoryID"), _ dst.Tables("Products").Columns("CategoryID")) Return dst
End Function |
Fill data to menu control
Sub PopulateMenu()
Dim dst As DataSet = GetMenuData() For Each masterRow As DataRow In
dst.Tables("Categories").Rows Dim masterItem As New MenuItem(masterRow("CategoryName").ToString()) Menu1.Items.Add(masterItem) For Each childRow As DataRow In
masterRow.GetChildRows("Children") Dim childItem As New MenuItem(childRow("ProductName").ToString()) masterItem.ChildItems.Add(childItem) Next Next End Sub |
Page Load
We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
Sub Page_Load()
If Not IsPostBack Then
PopulateMenu() End If End Sub |
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!