ASP2.0 SizeMapPath 添加自定义属性(target)
Posted on 2006-10-10 14:24 ∈鱼杆 阅读(1843) 评论(2) 编辑 收藏 所属分类: 工作(Work)![](https://i-blog.csdnimg.cn/blog_migrate/167015484ed17154d94bc99209c38cac.jpeg)
首先定义Web.sitemap文件(添加target属性):
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode url="~/SiteMapPath/default.aspx" title="默认显示" description="" target="_blank">
</siteMapNode>
<siteMapNode url="~/SiteMapPath/Add Target.aspx" title="ADD" description="" target="_blank">
</siteMapNode>
</siteMapNode>
</siteMap>
第二定义SizeMapPath 的 ItemDataBound的事件:
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode url="~/SiteMapPath/default.aspx" title="默认显示" description="" target="_blank">
</siteMapNode>
<siteMapNode url="~/SiteMapPath/Add Target.aspx" title="ADD" description="" target="_blank">
</siteMapNode>
</siteMapNode>
</siteMap>
protected
void
SiteMapPath1_ItemDataBound(object sender, SiteMapNodeItemEventArgs e)
{
HyperLink hlk;
if (e.Item.Controls[ 0 ] is HyperLink)
{
hlk = (HyperLink)e.Item.Controls[ 0 ];
hlk.Attributes[ " target " ] = e.Item.SiteMapNode[ " target " ];
}
}
测试一下:ok。其实通过这个方法还可以添加其他的属性。可以实现更多的效果,这里起个抛砖的作用。哈哈!
{
HyperLink hlk;
if (e.Item.Controls[ 0 ] is HyperLink)
{
hlk = (HyperLink)e.Item.Controls[ 0 ];
hlk.Attributes[ " target " ] = e.Item.SiteMapNode[ " target " ];
}
}