0

enter image description here

This is my simple menu which I created using the following code..

 <li><asp:LinkButton ID="lnkTesting" runat="server" PostBackUrl="~/Works/frmTesting.aspx">TESTING</asp:LinkButton></li>
 <li><asp:LinkButton ID="LinkButton5" runat="server">STYLES</asp:LinkButton></li>

I haven't used <asp:Menu>. My case is: I need to make the 5th menu "STYLES" to be loaded dynamically from the DB under the Menu "STYLES". Example would be like this ??

 STYLES
 Menu 1 
        Menu 1.1
                 Menu 1.1.1
                 Menu 1.1.2
        Menu 1.2
                 Menu 1.2.1
        Menu 1.3
 Menu 2

Those Menus will be loaded from DB. Menu 1.1 should contains only its content. How can I achieve this? I tried to build the 1st sub menu item using the following code but it didn't worked ..

MenuItem add = new MenuItem("STYLES");
    add.ChildItems.Add("Menu 1");

Any reference based on my needs pls????

Eugene Podskal
  • 10,270
  • 5
  • 31
  • 53
SRIRAM RAMACHANDRAN
  • 297
  • 3
  • 8
  • 23

3 Answers3

1

ok so my suggestion is like this, to create a dynamic menu i would have created a class that gets all the menus for a page and sub-menus and gives me back either a control( panel or what ever ) or an HTML code which can be placed in a literal control, and it would work something like this:

a call to GetMenus function will get all the option in the main menu and populate it to the control in each main option ( parent ) you need to get all its sub options and populate it to the parent option. if you break it down to small tasks its preaty easy to do.

im not giving you the code for it because i think its better for you to give it a try and then if you run into trouble we will help you further.

if you got questions please ask.

hope this helped

Liran
  • 591
  • 3
  • 13
  • thanks @Liran. I tried and made menus to be bound dynamically from DB. Problem would be CSS. Where the menus are displaying one after the other not like (Menu->submenu->submenu->submenu).. Need to figure out the problem. – SRIRAM RAMACHANDRAN Aug 27 '14 at 04:52
  • @SRIRAMRAMACHANDRAN when you create the menus add classes to them in the property CssClass, if you want to post what you got so far, i can have a look and help. if you will post the code it will help if you post HTML,CSS, and the code that generates the HTML – Liran Aug 27 '14 at 09:02
0

You can use

 <li><asp:LinkButton ID="LinkButton5" runat="server"><%#Eval ("Column Name") %></asp:LinkButton></li>

This will bind data from the DB column to each level of your menu. You will need to create your first menu level and bind that data to say, a column named "Category", then your sub menu items would be bound to a column such as "Type".

user3841709
  • 386
  • 6
  • 28
  • You should also be able to do this using using this method to bind the column names dynamically – user3841709 Aug 25 '14 at 14:22
  • Oh.. Is there no other possibilities?? – SRIRAM RAMACHANDRAN Aug 26 '14 at 04:07
  • does this not work for you? Are you going to use data from multiple columns in the database? And How many total list items are you going to have, a lot or just like 4 or 5? Using this method, your Menu 1 and Menu 2 would all be the values from one column like a "Category" column. Then when you create the sub menu, the menu 1.1, 1.2, 1.3 would be from another column. – user3841709 Aug 26 '14 at 12:11
  • You will also need a datasource control like SqlDataSource where you have a Select Query to retrieve the data for each column. – user3841709 Aug 26 '14 at 12:12
  • I'm sure there are a few other ways to do this, I am only familiar with this method and use the Eval ("Column Name") a lot – user3841709 Aug 26 '14 at 12:13
  • I took the necessary values from DB and thanks your code works for me in other way. The problem which I am facing now would be CSS. The menus are displaying one after the other(not like submenu within submenu).. Figuring out CSS part and I could't find any reference for menu having submenu with 3 columns(Menu->submenu->submenu->submenu) – SRIRAM RAMACHANDRAN Aug 27 '14 at 04:50
  • see here http://stackoverflow.com/questions/5899337/proper-way-to-make-html-nested-list – user3841709 Aug 27 '14 at 13:28
  • Is this problem fixed now? If so could you mark as answered – user3841709 Sep 01 '14 at 14:38
0

You don't even need CSS just to get a nested menu or list.

 <ul>
 <li>Coffee</li>
 <li>Tea
   <ul>
   <li>Black tea</li>
   <li>Green tea</li>
   </ul>
 </li>
 <li>Milk</li>

Use this structure. For every nested tag, you will have a new submenu

user3841709
  • 386
  • 6
  • 28