Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting the Navigation bar and the data from the SQL Server 2012 and I am using Visual Studio 2015 Enterprise Edition. The parent node of the menu bar is transferring to next page but when i required aspx page from inside a folder not transferring into the page.

What I have tried:

This foreach block is written in a function:
foreach (DataRowView row in view)
{
    MenuItem menuItem = new MenuItem(row["MenuName"].ToString(), row["MenuID"].ToString());
    menuItem.NavigateUrl = row["Menu_Url"].ToString();
    Menu1.Items.Add(menuItem);
    AddChildItems(table, menuItem);
}


AddChildItems Function:
DataView viewItem = new DataView(table);
viewItem.RowFilter = "Menu_Parent_ID= " + menuItem.Value;
foreach (DataRowView childView in viewItem)
{
    MenuItem childItem = new MenuItem(childView["MenuName"].ToString(),
    childView["MenuID"].ToString());
    childItem.NavigateUrl = childView["Menu_Url"].ToString();
    menuItem.ChildItems.Add(childItem);
    AddChildItems(table, childItem);
}


using this two functions i am getting data from SQL Server but when i initialized the aspx page separate folder and accessing the URL path from SQL Server it is not transferring the page what i am doing wrong can anyone explain me. This two functions are called in Master Page
Posted
Updated 21-Feb-18 23:33pm

1 solution

You need to store the urls in the Menu_Url field as virtual urls, which are urls in this format

~/Default.aspx
~/Product/View.aspx

basically it uses "~" as meaning the root of your site. When you set the NavigationUrl property of a server control like a link etc it understands this format and ensures the link is valid no matter where you are in the site.

If your next question is how to fix this without changing the data in your database, then it's vital to store data in the correct format in the first place. Don't store "bad" data then try and accommodate that bad data elsewhere, that just leads to all sorts of problems. Get your data right from the start and everything becomes easier.
 
Share this answer
 
v2
Comments
Member 8583441 22-Feb-18 5:38am    
Thanks a lot it's working

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