We Write

Home » Blog Details

Web Application Development Company - Multi Level Dropdown Menu

Multi Level Dropdown Menu

Multi Level Dropdown Menu

Multi Level Menu with ASP.NET, C#, jQuery and SQL Server

solution that I would like to share with others puzzled with the same as was one of my website development guys was having a tough time creating a multi level dropdown menu from database,
So I gave him this :
1. Database
We will be using 2 tables to achieve the same :
a. Category Table ( tbl_cat ):
Category_ID : Unique ID
Category_Name : Text
b. Table to hold category relations ( tbl_cat_rel )
Rel_ID : Unique ID
Category_ID : foreign key
Parent_ID : Parent Category ID
Sort_ID : In case you want to sort category display.

2. Stored Procedure

This part is bit tricky as we will be calculating number of childs a particular category holds
					

CREATE PROCEDURE sp_getCategory					

AS					

BEGIN					

Select a.Category_ID, a.Parent_ID, c.Category_Name, b.totalSubCats 					

from tbl_cat_rel as a LEFT OUTER JOIN 					

(SELECT Parent_ID, count(*) as totalSubCats 					

FROM tbl_cat_rel GROUP BY Parent_ID) as b 					

ON a.Category_ID = b.Parent_ID					

LEFT OUTER JOIN tbl_cat as c 					

on a.Category_ID = c.Category_ID					

ORDER BY a.Category_ID					

END					



3. jQuery

Although you can use any jQuery menu you find suitable, for this example I am using
DDSmooth menu available at : http://www.dynamicdrive.com/dynamicindex1/ddsmoothmenu.htm


4. Codes
I am assuming that you have selected a suitable menu Literal or similar to print its navigation values. In this example I will be using literal as follows :
					

<div id="smoothmenu1" class="ddsmoothmenu"> 					

<asp:Literal runat="server" ID="lt_navMenu"></asp:Literal>					

<br style="clear: left" />					

</div>					


And here are the CS codes :
					

// I am sure you know how to get data from tables :)					

this.createMenu(DSdataSet.Tables["tbl_categories"], 0); 					

					

private void createMenu(DataTable dt, int pID)					

{					

lt_navMenu.Text = lt_navMenu.Text + "&lt;ul&gt;";					

for (int i = 0; i < dt.Rows.Count; i++) //Loop until rows are still there.					

{					

if (Convert.ToInt32(dt.Rows[i]["ParentID"]) == pID) 					

{					

lt_navMenu.Text = lt_navMenu.Text + "<li><a href=\"/" +					

dt.Rows[i]["Category_Name"].ToString() + ".aspx \">" + 					

dt.Rows[i]["Category_Name"].ToString() + "</a>";					

					

//Till the time item has childs					

if (dt.Rows[i]["totalSubCats"] != DBNull.Value) 					

this.createMenu(dt, Convert.ToInt32(dt.Rows[i]["catID"]));					

lt_navMenu.Text = lt_navMenu.Text + "</li>";					

}					

}					

lt_navMenu.Text = lt_navMenu.Text + "</ul>";					

}					



The above was used in - http://www.svengg.co/


Till Next...
Jaswant.

SIMILAR POSTS

Squidoo Blog

Squidoo Lens or Blog!. What exactly are these? How is Squidoo related or co-related to Blogger. If I talk in simple language, there's more of a similarity than difference in basics of both. Both are the writer's own pages where he can write about anything, just anything. If you wish to earn from the same, you need to give to the audience whatever they are looking for. You can make as many pages as you want in both, write about topics of interest both your's and your... CONTINUE READING

Website Redesigning

Out in the web design and development market, there are number of web design firms that must be offering you creative logo designs, website designing, graphic designing. You might also get many calls and emails offering website redesigning. Then you peep at your existing website and ask yourself » Is a website overhaul really important? And why is it important ? We, at one of the best web design firms in India give you valid logical reasons for offering any... CONTINUE READING

Corporate Brand Identity

Corporate branding , to many means expense of about some thousands and lakhs of dollars, and to some a strategy meant for only highly learned professionals of the corporate world. There's actually much more to branding than just a famous name or image. Professional web design company, MegaSoftwares offers easy to understand and affordable corporate branding strategies. The right kind of branding adds to the actual value of the product or the service. It unbelievably... CONTINUE READING

Digital marketing - Understanding What and Why

Now, that you have reached to this page of India's best digital marketing company, let's begin with its'  What and Why!! There are a zillion websites on the internet today for every and any single search you make on the search engine. But, why is it so that few companies are better known, recognized and making good profits than the others. What's their secret of success? A good website isn't just great to look at. The motive of a website is much... CONTINUE READING

B2c B2b

Online B2C marketplace portals are the most widely looked for by end users as well as by companies aiming at better customer relationship and hence better revenue. Users are the ones who actually make your business run by their buying power. And what better if you reach upto them directly with your product information, product selling and get their direct feedbacks for a better online business. No doubt, that would improve your business efficiency and productivity.... CONTINUE READING
Contact Us
Dont' be shy, give us a shout.
We're always curious what fun projects and cool new people lurk around the corners of the web.

DROP US A LINE

Copyright © 2003-2018 MegaSoftwares - Web Design, Website Development and Web Marketing Agency in India
Go Top