views:

429

answers:

1

Hi there,

By adding a custom handler to the SiteMapResolve event, I can update sitemap url's on the fly, by some logic that I define.

This is ok for SiteMapPath controls, that appear to use this SiteMapResolve functionality... however I want to achieve a similar result for an asp.net Menu control that uses a SiteMapDataSource. Altering nodes with the SiteMapResolve handler doesn't have any effect.

Could anyone point me in the right direction? cheers :D

edit:sourcecode I've removed everything unnecessary and am left with the following - I must be misunderstanding something to do with the structure of the menuItemCollecton but it's always empty.

web.sitemap


<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="default.aspx" title="Homepage"  description="Home">
    <siteMapNode url="secondpage.aspx" title="Page 2" />
</siteMapNode>
</siteMap>

default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Menu runat=server ID=menu DataSourceid=dsSiteMap />
        <asp:SiteMapDataSource ID="dsSiteMap" runat="server" />
        <asp:Label runat=server id=lbMenuCount />
    </div>
    </form>
</body>
</html>

default.aspx.vb


Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lbMenuCount.text = menu.Items.Count End Sub End Class

A: 

Thank you for your pointers Muhammad, but I think I've cracked the problem.

I guess the menuItemCollection only looks at statically-defined items (i.e. within the code of the menu) wheras I'm linking to an XML datasource - so Muhammad's solution doesn't work

I have solved the problem by placing my code into the menu_MenuItemDataBound event - and am getting the results I want.

Thanks for all the help!

Tabloo Quijico
yes, you are absolutlty right, I have checked your example and found the same......... Good LUCK :)
Muhammad Akhtar