您好,我在母版页中有一个站点地图。我需要动态地将查询字符串传递给我的站点地图。有没有人有这方面的经验。 这是我的代码
的web.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="Employee Benefit" description="">
<siteMapNode url="~/Module/EB/Company/CompanyList.aspx" title="Company list" description="Company List" >
<siteMapNode url="~/Module/EB/Company/CompanyDetail.aspx" title="Company Detail" description="Company Detail" >
<siteMapNode url="~/Module/EB/Employee/EmployeeDetail.aspx" title="Employee Detail" description="Employee Detail" />
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>
Master.aspx
<asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Microsoft New Tai Lue"
Font-Size="0.9em" PathSeparator=" : " SkipLinkText="" Font-Bold="False"
style="font-family: 'Times New Roman', Times, serif; font-size: small"
Visible="True" >
<CurrentNodeStyle ForeColor="#333333" />
<NodeStyle Font-Bold="True" ForeColor="#284E98" />
<PathSeparatorStyle Font-Bold="True" ForeColor="#507CD1" />
<RootNodeStyle Font-Bold="True" ForeColor="#507CD1" />
</asp:SiteMapPath>
顺便说一下。我的站点地图可能有多个子siteMapNode。例如
companylist -> companydetail -> EmployeeDetail->.....
如何将查询字符串传递给其他子sitemapNope?
companylist -> companydetail?subID=1 -> EmployeeDetail?subID=2 ->....
答案 0 :(得分:0)
CodeBehind:
protected string CustomersURL
{
get
{
System.Text.StringBuilder url = new System.Text.StringBuilder("~/Module/EB/Company/CompanyList.aspx");
if (condition)
{
url.AppendFormat(@"?param1={0}", someparameter);
}
return url.ToString();
}
}
.ASPX:
<siteMapNode url='<%# CustomersURL %> title="Company list" description="Company List" >
编辑:
从MSDN查看以下说明,它可以解决您的问题:
http://msdn.microsoft.com/en-us/library/ms178425%28v=vs.100%29.aspx
private void Page_Load(object sender, EventArgs e)
{
// The ExpandForumPaths method is called to handle
// the SiteMapResolve event.
SiteMap.SiteMapResolve +=
new SiteMapResolveEventHandler(this.ExpandForumPaths);
}
private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e)
{
// The current node represents a Post page in a bulletin board forum.
// Clone the current node and all of its relevant parents. This
// returns a site map node that a developer can then
// walk, modifying each node.Url property in turn.
// Since the cloned nodes are separate from the underlying
// site navigation structure, the fixups that are made do not
// effect the overall site navigation structure.
SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
SiteMapNode tempNode = currentNode;
// Obtain the recent IDs.
int forumGroupID = GetMostRecentForumGroupID();
int forumID = GetMostRecentForumID(forumGroupID);
int postID = GetMostRecentPostID(forumID);
// The current node, and its parents, can be modified to include
// dynamic querystring information relevant to the currently
// executing request.
if (0 != postID)
{
tempNode.Url = tempNode.Url + "?PostID=" + postID.ToString();
}
if ((null != (tempNode = tempNode.ParentNode)) &&
(0 != forumID))
{
tempNode.Url = tempNode.Url + "?ForumID=" + forumID.ToString();
}
if ((null != (tempNode = tempNode.ParentNode)) &&
(0 != forumGroupID))
{
tempNode.Url = tempNode.Url + "?ForumGroupID=" + forumGroupID.ToString();
}
return currentNode;
}
...
// These methods are just placeholders for the example.
// One option is to use the HttpContext or e.Context object
// to obtain the ID.
private int GetMostRecentForumGroupID()
{
return 24;
}
private int GetMostRecentForumID(int forumGroupId)
{
return 128;
}
private int GetMostRecentPostID(int forumId)
{
return 317424;
}
您只需要在母版页的代码隐藏(在Page_Load事件上)挂钩到SiteMapResolveEventHandler,并提供一个返回自定义SiteMapNode的函数 - 例如示例中的ExpandForumPaths - 然后将其作为委托传递给SiteMapResolveEventHandler。