Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying the following code scenario to generate header menu but not getting anything.

Please help. Also tell me how can I add menu tab path to corresponding page dynamically?
C#
public void loadmastermenu()
{
    Panel pnl = new Panel();
    switch (Session["Username"].ToString())
    {
        case "Admin":          
            using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Constr"].ConnectionString))
            {               
                using (SqlDataAdapter adapt = new SqlDataAdapter("Select menuname from MMenu", con))
                {
                    DataSet ds = new DataSet();
                    adapt.Fill(ds);
                    Literal lt = new Literal();
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        lt.Text =Convert.ToString(ds.Tables[0].Rows[i]["MenuName"]);
                        pnl.Controls.Add(lt);
                        headerMenuTab.Controls.Add(pnl);
                    }             
                }
            }

            break;
Posted
v2
Comments
JoCodes 17-Sep-13 2:04am    
Where are you stuck or whats the error you are getting in case there is an error?
ajays3356 17-Sep-13 2:13am    
I am not getting anything on the div(headermenutab)..when i view in the browser its empty
JoCodes 17-Sep-13 3:00am    
"Select menuname from MMenu" retrieving records?
ajays3356 17-Sep-13 3:09am    
and how would i supposse to do that plz tell me...
JoCodes 17-Sep-13 3:21am    
wanted to know the select query has records fetched from the db which needs to populate your dynamic menu.
Place a break point check ds.Tables[0].Rows.Count and may also check the ds.Tables[0].Rows[i]["MenuName"] has value in it.

1 solution

I think this is the link what you are looking for...

dynamically bind menus in master page with the help of database[^]
 
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