Asp2.0 sizemappath add custom attributes (target)

Source: Internet
Author: User
The company project needs to add the navigation bar function of the topic, and naturally comes up with the sitemappath control (haha I prefer breadcrumb's breadcrumb name ). However, some links need to be opened in a new window because of project requirements. After searching for half a day, I didn't find that sitemappath can be set. It cannot be defined in Web. sitemap. But think about whether you can add this attribute when binding data. In fact, it's nothing more than HTML. Code . After trying to find OK.
First, define the Web. sitemap file (add the target attribute): <? 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 =" Default display "Description = "" Target = "_ blank">
</Sitemapnode>
<Sitemapnode url = "~ /Sitemappath/Add target. aspx "Title =" add "Description =" "target =" _ blank ">
</Sitemapnode>
</Sitemapnode>
</Sitemap>

second, define the itemdatabound event of sizemappath: protected void sitemappath1_itemdatabound (Object sender, sitemapnodeitemeventargs e)
{< br> hyperlink hlk;
If (E. item. controls [ 0 ] Is hyperlink)
{

Hlk=(Hyperlink) E. Item. controls [0];
Hlk. attributes ["Target"]=E. Item. sitemapnode ["Target"];
}
}

Test: OK. In fact, other attributes can be added through this method. More results can be achieved. Here, it plays a role of throwing bricks. Haha!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.