Click here to Skip to main content
15,881,852 members
Articles / Web Development / ASP.NET

TwoColorsMenu - The fastest menu in the world

Rate me:
Please Sign up or sign in to vote.
4.61/5 (20 votes)
10 Dec 2007CPOL2 min read 49.6K   1.1K   87  
This article will demo the fastest way to create a menu for your web page with the TwoColorsMenu.
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="OboutInc.TwoColorsMenu" %>
<%@ Page Language="c#" Debug="true" %>

<SCRIPT LANGUAGE="c#" Runat="server">
	void Page_Load(object sender, System.EventArgs e)
	{
		// declare the menu and set its properties
		TwoColorsMenu tcm = new TwoColorsMenu();
		tcm.ID = "TwoColorsMenu1";
		
		// add the menu to page
		Page.Controls.Add(tcm);

		string sConnectionString;
		OleDbDataReader oReader;
		
		// set the connection string
		sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../App_Data/DBDEMO.mdb");
		OleDbConnection Cn = new OleDbConnection(sConnectionString);
		
		// The database has one table called items containing both parent items and menu items
		// LEVEL shows what level the item is at (0 - parent item, 1 - belongs to menu attached to parent item, etc)
		// ORDER sets what is the item's order in the current menu (1 - first item, 2 - second item, etc.)
		// it is very important to add parent elements first, then level 1 items, then level 2 items, etc.
		string SQL = "SELECT * FROM Items ORDER BY [LEVEL], [ORDER]";
		OleDbCommand Com = new OleDbCommand(SQL,Cn);
		Cn.Open();
		oReader = Com.ExecuteReader();

		// Populate TCM.
		while (oReader.Read()) 
		{
			// if PARENTID is null, we're adding a parent element, otherwise it's a menu item
			tcm.Add(oReader.IsDBNull(oReader.GetOrdinal("PARENTID")) ? null : oReader.GetString(oReader.GetOrdinal("PARENTID")), 
					oReader.GetString(oReader.GetOrdinal("ID")),
					oReader.IsDBNull(oReader.GetOrdinal("HTML")) ? "" : oReader.GetString(oReader.GetOrdinal("HTML")),
					oReader.IsDBNull(oReader.GetOrdinal("URL")) ? null : oReader.GetString(oReader.GetOrdinal("URL")),
					oReader.IsDBNull(oReader.GetOrdinal("URLTARGET")) ? null : oReader.GetString(oReader.GetOrdinal("URLTARGET")));
		}

		oReader.Close();
		Cn.Close();
	}
</SCRIPT>

<HTML>
	<head>
    <title>TwoColorsMenu - Database Demo C#</title>
</head>
<body style="font: Tahoma 11px;">
	<h2>Obout TwoColorsMenu - Populating from Database using C#</h2>
	<br />
	<a class="examples" href="Default.aspx?type=CSHARP">� Back to examples</a>
	<br />
	<br />
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Unknown
I am Ned Thompson, 26 years old. I am working at obout inc as web component developer. I am really good at ASP.NET and Javascript.


Comments and Discussions