Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
Tutorial RSS
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Charts
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Controls - SQL Database Driven Menu in ASP.Net (VB.NET)
SQL Database Driven Menu in ASP.Net (VB.NET)


ASP.NET Controls Tutorial

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

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

Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!

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

If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

Page Load

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!

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!



 
  Developer Resources







Server Intellect Rocks