What Sothink DHTML Menu Can Do for You?

 

  Back Home Next

 

Download Menu Source
  Donwload Sothink DHTML Menu

 

VB.NET sample of dynamic menu created from database

Part 1: Sample Instruction


To create a dynamic menu from database, you can input some condition clauses using either CGI (ASP, PHP, and etc.) or JavaScript language, that is, to input the Prefix or Suffix for a menu item in the Menu Item > Condition dialog.

You can view the following menu on the web server that supports VB.Net.

As you see, in this sample, the menu contains 3 levels: the top level showing the categories,one of the sub level showing the products,and the other showing the tamplates.
The final result that you are seeing is just got from database.

Below is the diagram of the database.


Back to top

 

Part 2: Steps


The following are the steps of this example:

(Before creating the menu, you should make a database containing the information of the categories , the products and the templates.)

1. Create a menu from Blank. Choose "Menu Item > General", select "HTML". Input <%=rsCat(Name)%> in the context box.


2. Click "Condition" in "Menu Item".



3. In "Menu Item > Condition", input the prefix and suffix for the menu item.



Note: when you add the condition, you may get a warning message in DHTML Menu. That's because the condition code is server-side code which can not be processed by the browser directly. The warning will not show when you add the menu to an ASP page that is supported by server. You can uncheck "Preview > Enable Auto-Refresh" to avoid seeing the warnings.
Tips: To prevent this error popping up, you can add the JavaScript comment delimiters /* and */ to the Prefix as well as Suffix. In that way the preview ignores the extra code and the code works well on the server side processing.

For example:
Prefix:
/*
<%@ Import Namespace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDb" %>
<%
Dim con As OleDb.OleDbConnection
Dim strConnect As String="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(".\") & "\products.mdb;"
con= New System.Data.OleDb.OleDbConnection(strConnect)
dim rsCat as OleDb.OleDbDataAdapter = new OleDb.OleDbDataAdapter("select * from category",con)
Dim dsCat As New DataSet
Dim drCat As DataRow
Dim dtCat As DataTable
rsCat.Fill(dsCat)
dtCat = dsCat.Tables(0)
Dim i as Integer
For i = 0 to dtCat.Rows.Count - 1
drCat = dtCat.Rows(i)
Dim CatName = drCat("name")
%>
*/

Suffix:
/*
<%Next i%>
*/

4. Click "Add" button to add a sub item of it. Change the item type to "HTML", then input <%=ProName%> . In the link field, input <%=ProLink%>.



5. Click "Condition" in "Menu Item" and input the prefix and suffix for the menu item.

6. Click "Add" button to add a sub item of it. Change the item type to "HTML", then input <%=TepName%> . In the link field, input <%=TepLink%>.

7. Click "Condition" in "Menu Item" and input the prefix and suffix for the menu item.


Note: Normally in order to optimize the menu code, if several menu items have the same property, only one item's property code is recorded and other items take reference of its property code. If we add a condition to this item, there is possibility that it will be invisible when its condition is not met. And its property code can not be referenced by other items either. This will cause the whole menu can not work correctly. Please do check "This item may be invisible at run-time" to avoid the problem.

Back to top

 

Part 3: Code Explanation

This is the source code at the beginning of this sample page.

Code

Explanation

   

<%@ Import Namespace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDb" %>
<%
Dim con As OleDb.OleDbConnection
Dim strConnect As String="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(".\") & "\products.mdb;"
con= New System.Data.OleDb.OleDbConnection(strConnect)
dim rsCat as OleDb.OleDbDataAdapter = new OleDb.OleDbDataAdapter("select * from category",con)

Dim dsCat As New DataSet
Dim drCat As DataRow
Dim dtCat As DataTable
rsCat.Fill(dsCat)

 


Connect with the database.
dtCat = dsCat.Tables(0)
%>
Retrieve recordset from the category table.

 

Back to top

Download Menu Source
  Donwload Sothink DHTML Menu

Sothink ist das Markenzeichen von SourceTec Software Co., LTD.
Flash ist das Markenzeichen von Adobe.
Sothink Software: SWF Decompiler, DHTML Menü, Baum Menü, JavaScript Web Scroller, SWF Quicker, SWF Easy, Quicker für Silverlight, Logo Maker

Verbindungen Kommentar Datenschutz AGB Sitemap