C
Carlos Albert
Hello world,
I'm trying to populate an ASP.NET 2 menu control, but so far no luck. The
first problem I find is that they are for C#... and I work using VB.
Tried this way: http://aspalliance.com/822 , translating the code (that I
post at the end of the msj) but all I got is a menu with two items level 1
that says "MenuItem". Nothing else.
And tried to use this
http://www.codeproject.com/cs/menu/PopulatingMenuControlASP2.asp but don't
know how to translate it.
Any help will gonna be very much welcome...
Shared Function Menu() As String
Dim ds As New DataSet
Dim miConexion As New
SqlConnection(ConnectionStrings("web").ConnectionString)
Dim miSelect As String = "SELECT ID, d_Nombre, d_Descripcion,
c_ParentID FROM Prueba1.dbo.MenuOnline"
Dim miDataAdapter As New SqlDataAdapter(miSelect, miConexion)
miDataAdapter.Fill(ds)
If miConexion.State = ConnectionState.Open Then miConexion.Close()
miConexion.Dispose()
miDataAdapter.Dispose()
ds.DataSetName = "Menues"
ds.Tables(0).TableName = "MenuOnline"
Dim miRelation As New DataRelation("ParentChild",
ds.Tables("MenuOnline").Columns("ID"),
ds.Tables("MenuOnline").Columns("c_ParentID"), True)
miRelation.Nested = True
ds.Relations.Add(miRelation)
Menu = ds.GetXml
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim miXmlDS as New XmlDataSource
miXmlDS.TransformFile = "../menu/MenuPrincipal.xsl"
miXmlDS.XPath = "MenuItems/MenuItem"
miXmlDS.Data = Menu
Menu.DataSource = miXmlDS
Menu.DataBind()
End Sub
The function returns this:
<Menues>
<MenuOnline>
<ID>1</ID>
<d_Nombre>Home</d_Nombre>
</MenuOnline>
<MenuOnline>
<ID>2</ID>
<d_Nombre>Hi</d_Nombre>
<MenuOnline>
<ID>3</ID>
<d_Nombre>How</d_Nombre>
<c_ParentID>2</c_ParentID>
</MenuOnline>
<MenuOnline>
<ID>4</ID>
<d_Nombre>are</d_Nombre>
<c_ParentID>2</c_ParentID>
</MenuOnline>
<MenuOnline>
<ID>5</ID>
<d_Nombre>you</d_Nombre>
<c_ParentID>2</c_ParentID>
</MenuOnline>
</MenuOnline>
</Menues>
And the xsl has this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml" indent="yes" encoding="utf-8"/>
<!-- Find the root node called Menus
and call MenuListing for its children -->
<xsl:template match="/Menues">
<MenuItems>
<xsl:call-template name="MenuListing" />
</MenuItems>
</xsl:template>
<!-- Allow for recusive child node processing -->
<xsl:template name="MenuListing">
<xsl:apply-templates select="MenuOnline" />
</xsl:template>
<xsl:template match="MenuOnline">
<MenuItem>
<!-- Convert Menu child elements to MenuItem attributes -->
<xsl:attribute name="d_Nombre">
<xsl:value-of select="d_Nombre"/>
</xsl:attribute>
<xsl:attribute name="ToolTip">
<xsl:value-of select="d_Descripcion"/>
</xsl:attribute>
<xsl:attribute name="NavigateUrl">
<xsl:text>?Sel=</xsl:text>
<xsl:value-of select="d_Nombre"/>
</xsl:attribute>
<!-- Call MenuListing if there are child Menu nodes -->
<xsl:if test="count(Menu) > 0">
<xsl:call-template name="MenuListing" />
</xsl:if>
</MenuItem>
</xsl:template>
</xsl:stylesheet>
I'm trying to populate an ASP.NET 2 menu control, but so far no luck. The
first problem I find is that they are for C#... and I work using VB.
Tried this way: http://aspalliance.com/822 , translating the code (that I
post at the end of the msj) but all I got is a menu with two items level 1
that says "MenuItem". Nothing else.
And tried to use this
http://www.codeproject.com/cs/menu/PopulatingMenuControlASP2.asp but don't
know how to translate it.
Any help will gonna be very much welcome...
Shared Function Menu() As String
Dim ds As New DataSet
Dim miConexion As New
SqlConnection(ConnectionStrings("web").ConnectionString)
Dim miSelect As String = "SELECT ID, d_Nombre, d_Descripcion,
c_ParentID FROM Prueba1.dbo.MenuOnline"
Dim miDataAdapter As New SqlDataAdapter(miSelect, miConexion)
miDataAdapter.Fill(ds)
If miConexion.State = ConnectionState.Open Then miConexion.Close()
miConexion.Dispose()
miDataAdapter.Dispose()
ds.DataSetName = "Menues"
ds.Tables(0).TableName = "MenuOnline"
Dim miRelation As New DataRelation("ParentChild",
ds.Tables("MenuOnline").Columns("ID"),
ds.Tables("MenuOnline").Columns("c_ParentID"), True)
miRelation.Nested = True
ds.Relations.Add(miRelation)
Menu = ds.GetXml
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim miXmlDS as New XmlDataSource
miXmlDS.TransformFile = "../menu/MenuPrincipal.xsl"
miXmlDS.XPath = "MenuItems/MenuItem"
miXmlDS.Data = Menu
Menu.DataSource = miXmlDS
Menu.DataBind()
End Sub
The function returns this:
<Menues>
<MenuOnline>
<ID>1</ID>
<d_Nombre>Home</d_Nombre>
</MenuOnline>
<MenuOnline>
<ID>2</ID>
<d_Nombre>Hi</d_Nombre>
<MenuOnline>
<ID>3</ID>
<d_Nombre>How</d_Nombre>
<c_ParentID>2</c_ParentID>
</MenuOnline>
<MenuOnline>
<ID>4</ID>
<d_Nombre>are</d_Nombre>
<c_ParentID>2</c_ParentID>
</MenuOnline>
<MenuOnline>
<ID>5</ID>
<d_Nombre>you</d_Nombre>
<c_ParentID>2</c_ParentID>
</MenuOnline>
</MenuOnline>
</Menues>
And the xsl has this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml" indent="yes" encoding="utf-8"/>
<!-- Find the root node called Menus
and call MenuListing for its children -->
<xsl:template match="/Menues">
<MenuItems>
<xsl:call-template name="MenuListing" />
</MenuItems>
</xsl:template>
<!-- Allow for recusive child node processing -->
<xsl:template name="MenuListing">
<xsl:apply-templates select="MenuOnline" />
</xsl:template>
<xsl:template match="MenuOnline">
<MenuItem>
<!-- Convert Menu child elements to MenuItem attributes -->
<xsl:attribute name="d_Nombre">
<xsl:value-of select="d_Nombre"/>
</xsl:attribute>
<xsl:attribute name="ToolTip">
<xsl:value-of select="d_Descripcion"/>
</xsl:attribute>
<xsl:attribute name="NavigateUrl">
<xsl:text>?Sel=</xsl:text>
<xsl:value-of select="d_Nombre"/>
</xsl:attribute>
<!-- Call MenuListing if there are child Menu nodes -->
<xsl:if test="count(Menu) > 0">
<xsl:call-template name="MenuListing" />
</xsl:if>
</MenuItem>
</xsl:template>
</xsl:stylesheet>