公司项目需要添加栏目导航条的功能,很自然的就想到了SiteMapPath控件(哈哈我更喜欢breadcrumb 面包屑这个名称)。但因为项目的需要某些链接需要在新的窗口打开链接。找了半天没发现SiteMapPath可以设置,在Web.sitemap中也没办法定义。但想想在绑定数据的时候是否可以添加上这个属性,其实无非到最后都是一些HTML代码吗。经过尝试发现OK.
首先定义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的事件:
 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。其实通过这个方法还可以添加其他的属性。可以实现更多的效果,这里起个抛砖的作用。哈哈!

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2022-01-15
  • 2021-08-30
  • 2021-09-25
  • 2022-01-13
猜你喜欢
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2021-06-01
  • 2022-12-23
相关资源
相似解决方案