Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frnds,

I need to bind Css Menu with our database for viewing menu in our application.. I finished almost but need some help from you. Below is my sample Code

<br />
<div><br />
<div class = 'Column'><br />
  <a href=''></a><br />
  <a href=''></a><br />
</div><br />
<div class ='column'><br />
  <a href=''></a><br />
  <a href=''></a><br />
<div><br />
<div><br />


from the above code that column class div should split to split our dropdown menu. I tried using flag but wont get it correctly. i tried to bind the in while loop so in while loop the
should display after binding 10 rows that should close and again should bind.
Posted
Comments
The Doer 24-Jun-13 5:02am    
Why dont you go for Menu Control of ASP .net?

1 solution

The simplest solution to this is - put a Label say "LabelMenu" in aspx page. create a member function in .cs page.
Within that function write code to do the the following task:

1. Get your menu data from your database and bind them to a dataset.
2. Create a string type variable where you can write your html part of the menu. Initialize it with the intial HTML. Say - string MyString = "<div class='mystyle'>";
3. Write a foreach to loop to get thru the dataset and use the string type variable to integrate the html menu with menu name and URL fetched from database.
4. once the dataset is traversed, write the closing HTML tags, write the sting to the Label.
5. Your menu is ready.

Please see the below example.
C#
private void fnPopulateMenu()
{
    DataSet DsMenu = new DataSet();
    string TblMenu = "<table class='MenuCss'><tr>";
    //Fetch and Bind data to DataSet
    .....
    foreach (string Drow in DsMenu.Tables[0].Rows)
    {
         TblMenu += "<td><a href='"+Drow["MenuLink"] +"'>"+Drow["MenuName"]+"</a></td>";
    }
    TblMenu = "</tr></table>";
    LabelMenu.Text = TblMenu;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900