ASP.NET Include QueryString Parameters In SiteMapPath

I am using the SiteMapPath control on an ASP.NET application to create a breadcrumbs effect on the header of my pages. The basic example that I based my code on simply displayed the title and url from the web.sitemap file.

<asp:SiteMapPath ID="SiteMapPath1" runat="server">

<NodeTemplate>
<asp:HyperLink ID="HyperLink2" runat="server"
Text='<%# Eval("title") %>' NavigateUrl='<%# Eval("url") %>' />
</NodeTemplate>

</asp:SiteMapPath>

One of my pages has an id parameter e.g. member_view.aspx?id=2 and I wanted to include this in the breadcrumbs. Initially I didn't think of modifying the NodeTemplate to accomplish this. Doing a search led me to examples that used the SiteMapResolveEventHandler (which was shown to be problematic) or creating your own SiteMapProvider (which seemed like too much for something so simple). After thinking really hard I realised I could simple modify the NodeTemplate to achieve what I wanted. e.g.

<NodeTemplate>

<asp:HyperLink ID="HyperLink2" runat="server"
Text='<%# Eval("url").ToString()=="/my_website/member_view.aspx"?(Request["id"]!=null?"Member Update (" + Request["id"] + ")":"Member Add"):Eval("title") %>' NavigateUrl='<%# Eval("url").ToString()=="/my_website/member_view.aspx"?Request.Url:Eval("url") %>' />

</NodeTemplate>

4 comments:

  1. hey buddy, this help a lot. Thanks for the post.

    ReplyDelete
  2. I've been working on this all day - when I finally found your example.

    I changed mine to assign attributes in the code behind but your example steered me in the right direction - THANKS!

    ReplyDelete
  3. Give it a try and let us know what errors you get.

    ReplyDelete