Thank you for the response q. When I do the following:
<DynamicItemTem plate>
<asp:Label runat="server" ID="Label1" Text='<%# Eval("Text") %>'
Style='<%# styles( Eval("valuepath ") ) %>' />
</DynamicItemTemp late>
I receive the following error:
Error 3 'ASP.masterpage _master.styles' is a 'field' but is used like a
'method' D:\Visual Studio\CustomMe nuItems.CS\Mast erPage.master 24
I've included the entire source for the new page (the one that genrates
the error) below along with the contents of my sitemap file in case it
helps. Thanks again.
MasterPage.mast er
===============
<%@ Master Language="C#" AutoEventWireup ="true"
CodeFile="Maste rPage.master.cs " Inherits="Maste rPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<script runat="server">
public static System.Collecti ons.Generic.Dic tionary<string, string>
styles = new System.Collecti ons.Generic.Dic tionary<string, string>();
protected void Menu1_MenuItemD ataBound(object sender, MenuEventArgs
e)
{
styles[e.Item.ValuePat h] =
((SiteMapNode)e .Item.DataItem)["style"];
}
</script>
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div id="Head">
<asp:Menu ID="Menu1" runat="server"
DataSourceID="S iteMapDataSourc e1"
OnMenuItemDataB ound="Menu1_Men uItemDataBound" Orientation="Ho rizontal"
StaticDisplayLe vels="2">
<DynamicItemTem plate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( Eval("valuepath ") ) %>' />
</DynamicItemTemp late>
<StaticItemTemp late>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( Eval("valuepath ") ) %>' />
</StaticItemTempl ate>
</asp:Menu>
<asp:SiteMapDat aSource ID="SiteMapData Source1"
runat="server" />
</div>
<div>
<asp:ContentPla ceHolder ID="ContentPlac eHolder1"
runat="server">
</asp:ContentPlac eHolder>
</div>
</form>
</body>
</html>
Web.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microso ft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.as px" title="Home" description="Ma in
page">
<siteMapNode url="Page1.aspx " title="Page1" description="Pa ge1
Description" style="backgrou nd-color:Blue; color:White;">
<siteMapNode url="Page1.1.as px" title="Page1.1"
description="Pa ge1 Description" style="backgrou nd-color:Yellow;
color:Black;" />
</siteMapNode>
<siteMapNode url="Page2.aspx " title="Page2" description="Pa ge2
Description" style="backgrou nd-color:Black; color:Yellow;" />
</siteMapNode>
</siteMap>
q wrote:
You don't have to change anything in the ASP.NET controls.
eval("valuepath ") may look like VB, but it's ASP.NET.
k.************* @gmail.com wrote:
Hi All,
I'm trying to convert some ASP.NET code that I found at
http://weblogs.asp.net/dannychen/arc...02/432190.aspx from VB
to C#.
I've managed to convert the portion that is in the <script></script>
section of the file fine (I think) but I've been unable to convert the
code in each of the <asp:Label /tags so far. Can anyone point me in
the right direction?
The only thing that the code is supposed to do is allow for a custom
CSS tags to be added to the sitemap file for the site so that each menu
item can have its own CSS. The original code along with the section
that I have converted is shown below.
Thanks,
Kris
Original Code
===========
<%@ Master Language="VB" CodeFile="Maste rPage.master.vb "
Inherits="Maste rPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<script runat="server">
REM http://weblogs.asp.net/dannychen/arc...02/432190.aspx
Shared styles As New System.Collecti ons.Generic.Dic tionary(Of
String, String)
Protected Sub Menu1_MenuItemD ataBound(ByVal sender As Object, _
ByVal e As
System.Web.UI.W ebControls.Menu EventArgs)
styles(e.Item.V aluePath) = CType(e.Item.Da taItem,
SiteMapNode)("s tyle")
End Sub</script>
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Menu ID="Menu1" runat="server"
DataSourceID="S iteMapDataSourc e1" Orientation="Ho rizontal"
StaticDisplayLe vels="2"
OnMenuItemDataB ound="Menu1_Men uItemDataBound" >
<StaticItemTemp late>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath ") ) %>' />
</StaticItemTempl ate>
<DynamicItemTem plate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath ") ) %>' />
</DynamicItemTemp late>
</asp:Menu>
<asp:SiteMapDat aSource ID="SiteMapData Source1" runat="server"
/>
<div>
<asp:ContentPla ceHolder ID="ContentPlac eHolder1"
runat="server">
</asp:ContentPlac eHolder>
</div>
</form>
</body>
</html>
Converted Section
==============
<script runat="server">
public static System.Collecti ons.Generic.Dic tionary<string, string>
styles = new System.Collecti ons.Generic.Dic tionary<string, string>();
protected void Menu1_MenuItemD ataBound(object sender, MenuEventArgs
e)
{
styles[e.Item.ValuePat h] =
((SiteMapNode)e .Item.DataItem)["style"];
}
</script>