473,508 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populating the Menu - Navigation Control

MMA
How do I populate the menu control in 2.0 from a database. I know this can be
done with the Tree Control. Any code snippets? Thanks in advance.
Sep 20 '06 #1
2 1602
Just check the following snippet of code and let me know whether this is
usefule to you

private void PopulateMenu()
{
DataSet ds = GetDataSetFromDatabase();
Menu menu = new Menu();

foreach (DataRow parentItem in ds.Tables["Categories"].Rows)
{
MenuItem categoryItem = new MenuItem((string)parentItem["CategoryName"]);
menu.Items.Add(categoryItem);

foreach (DataRow childItem in parentItem.GetChildRows("Children"))
{
MenuItem childrenItem = new MenuItem((string)childItem["ProductName"]);
categoryItem.ChildItems.Add(childrenItem);
}
}
}

private DataSet GetDataFromDatabase()
{
SqlConnection myConnection = new SqlConnection(GetConnectionString());
SqlDataAdapter adCat = new SqlDataAdapter("SELECT * FROM Categories",
myConnection);
SqlDataAdapter adProd = new SqlDataAdapter("SELECT * FROM Products",
myConnection);

DataSet ds = new DataSet();
adCat.Fill(ds, "Categories");
adProd.Fill(ds, "Products");
ds.Relations.Add("Children",
ds.Tables["Categories"].Columns["CategoryID"],
ds.Tables["Products"].Columns["CategoryID"]);
return ds;
}
--
Thanks & Regards,
Sundar Narasimman
Technology Specialist

"MMA" wrote:
How do I populate the menu control in 2.0 from a database. I know this can be
done with the Tree Control. Any code snippets? Thanks in advance.

Sep 21 '06 #2
on this page is an example of another way of progrmmatically populating
a Menu control, without using relations

http://authors.aspalliance.com/aspxt...vigateUrl.aspx

Sep 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1615
by: Sisnaz | last post by:
I'm working with 2005 Beta 2 and I'm sure this is a trivial question but for the life of me I can't figure out. I placed a menu navigation componet on my master page and defined the navigation...
0
1297
by: Andrew Polo | last post by:
Dear Sirs, I'm using Navigation Menu control on one of my Web Pages (.NET Framework 2.0). Everything is fine as far as I'm not using it within Master Page. If I make my page as a context of Master...
9
1377
by: Jay | last post by:
I have an asp menu control with menu items navigateUrl set to come back to the same aspx page but with different values in a url token. this works, but it is causing all my asp controls to loose...
11
1696
by: Rickie | last post by:
Dear fellow software engineers, Is the web menu in asp 2.0 essentielle a useless control ? How many people( including msdn itself) are using server menu controls? Its a menu which always...
3
2085
by: John | last post by:
Hi there, I was reading an article (http://avenuea-razorfish.com/articles/TheAll-MenuNavigation_Turbek.pdf) on 'all-menu navigation' and I'd like to try and implement this in my site. Can...
9
6552
by: =?Utf-8?B?ZHBvbXQ=?= | last post by:
Hello, I have a problem with the ASP.NET menu when rendered in IE7: If the menu is inside a div with style="position:fixed;top:3em;", all the submenus also have the top:3em. Is this an IE7...
1
7691
by: Fabx | last post by:
Hallo, sorry for my english. I want to build a navigation menu with the repeat control, the items of menu are in a table of database. All items of the menu have class="MenuLink", but the...
0
1304
by: RJN | last post by:
Hi I'm using the asp:Menu control in the sharepoint master page for displaying the site navigation. The site navigations are getting displayed. On clicking one of the menu items in the...
3
1976
by: =?Utf-8?B?VG9tIFc=?= | last post by:
When I mouse over a Menu Control based navigation area the drop-down selection list appears instantaneously. Is there a way to make it less sensitive, so that it delays (even a fraction of a second...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.