Click here to Skip to main content
15,905,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a menu item which is generated at run time.
there are main menu & their chailds,chailds has its navigate url but i have to assign url to main menu for home page...


for this i have done this codding


C#
connection(); 
            SqlCommand cmd = new SqlCommand("menus", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@code", Session["username"].ToString());
            SqlDataAdapter adap = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adap.Fill(ds);
            MainMenu.Items.Clear();
            ds.Relations.Add("Children", ds.Tables[0].Columns["menu_name"], ds.Tables[1].Columns["menu_name"],false);
            foreach (DataRow masterRow in ds.Tables[0].Rows)
            {
                MenuItem masterItem = new MenuItem(" " + (string)masterRow["menu_name"] + " ");
                MainMenu.Items.Add(masterItem);
                foreach (DataRow childRow in masterRow.GetChildRows("Children"))
                {

                    MenuItem childItem = new MenuItem((string)childRow["menuitem_name"]);
                    masterItem.ChildItems.Add(childItem);
                    childItem.NavigateUrl = ((string)childRow["menu_url"]);
                }
            }


Now How can i assine the url to main menu..
plz help..
Posted
Updated 30-Nov-11 23:04pm
v2
Comments
D K N T H 1-Dec-11 5:05am    
edited code tag

1 solution

Did you try this?
C#
foreach (DataRow masterRow in ds.Tables[0].Rows)
{
    MenuItem masterItem = new MenuItem(" " + (string)masterRow["menu_name"] + " ");
    masterItem.NavigateUrl = ((string)masterRow["menu_url"]);//This line
    MainMenu.Items.Add(masterItem);
    foreach (DataRow childRow in masterRow.GetChildRows("Children"))
    {

        MenuItem childItem = new MenuItem((string)childRow["menuitem_name"]);
        masterItem.ChildItems.Add(childItem);
        childItem.NavigateUrl = ((string)childRow["menu_url"]);
    }
}
 
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