K
k.vanderstarren
Hi All,
I'm trying to convert some ASP.NET code that I found at
http://weblogs.asp.net/dannychen/archive/2005/12/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="MasterPage.master.vb"
Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script runat="server">
REM http://weblogs.asp.net/dannychen/archive/2005/12/02/432190.aspx
Shared styles As New System.Collections.Generic.Dictionary(Of
String, String)
Protected Sub Menu1_MenuItemDataBound(ByVal sender As Object, _
ByVal e As
System.Web.UI.WebControls.MenuEventArgs)
styles(e.Item.ValuePath) = CType(e.Item.DataItem,
SiteMapNode)("style")
End Sub</script>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Menu ID="Menu1" runat="server"
DataSourceID="SiteMapDataSource1" Orientation="Horizontal"
StaticDisplayLevels="2"
OnMenuItemDataBound="Menu1_MenuItemDataBound">
<StaticItemTemplate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath") ) %>' />
</StaticItemTemplate>
<DynamicItemTemplate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath") ) %>' />
</DynamicItemTemplate>
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"
/>
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1"
runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Converted Section
==============
<script runat="server">
public static System.Collections.Generic.Dictionary<string, string>
styles = new System.Collections.Generic.Dictionary<string, string>();
protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs
e)
{
styles[e.Item.ValuePath] =
((SiteMapNode)e.Item.DataItem)["style"];
}
</script>
I'm trying to convert some ASP.NET code that I found at
http://weblogs.asp.net/dannychen/archive/2005/12/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="MasterPage.master.vb"
Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script runat="server">
REM http://weblogs.asp.net/dannychen/archive/2005/12/02/432190.aspx
Shared styles As New System.Collections.Generic.Dictionary(Of
String, String)
Protected Sub Menu1_MenuItemDataBound(ByVal sender As Object, _
ByVal e As
System.Web.UI.WebControls.MenuEventArgs)
styles(e.Item.ValuePath) = CType(e.Item.DataItem,
SiteMapNode)("style")
End Sub</script>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Menu ID="Menu1" runat="server"
DataSourceID="SiteMapDataSource1" Orientation="Horizontal"
StaticDisplayLevels="2"
OnMenuItemDataBound="Menu1_MenuItemDataBound">
<StaticItemTemplate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath") ) %>' />
</StaticItemTemplate>
<DynamicItemTemplate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath") ) %>' />
</DynamicItemTemplate>
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"
/>
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1"
runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Converted Section
==============
<script runat="server">
public static System.Collections.Generic.Dictionary<string, string>
styles = new System.Collections.Generic.Dictionary<string, string>();
protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs
e)
{
styles[e.Item.ValuePath] =
((SiteMapNode)e.Item.DataItem)["style"];
}
</script>