使用SQL Server URL路径的菜单导航 [英] Menu navigation using SQL server URL path

查看:200
本文介绍了使用SQL Server URL路径的菜单导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从SQL Server 2012获取导航栏和数据,并且正在使用Visual Studio 2015 Enterprise Edition.菜单栏的父节点正在传输到下一页,但是当我需要文件夹内部的aspx页面不能传输到该页面时.

我尝试过的事情:

这个foreach块是用函数编写的:

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函数:



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);
}



使用这两个功能,我从SQL Server获取数据,但是当我初始化aspx页面单独的文件夹并从SQL Server访问URL路径时,它没有传输该页面,我做错了任何人都可以解释一下我.在母版页中调用这两个函数



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

推荐答案

您需要将Menu_Url字段中的网址存储为虚拟网址,这些网址是这种格式的网址

〜/Default.aspx
〜/Product/View.aspx

基本上,它使用〜"作为您网站的根目录.当您设置服务器控件(如链接等)的NavigationUrl属性时,它将理解这种格式,并确保无论您在站点中的位置如何,链接都是有效的.

如果您的下一个问题是如何在不更改数据库中数据的情况下解决此问题,那么至关重要的是首先以正确的格式存储数据.不要存储不良"数据,然后尝试在其他地方容纳这些不良数据,这只会导致各种问题.从一开始就获取正确的数据,一切将变得更加容易.
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.


这篇关于使用SQL Server URL路径的菜单导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆