473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Populating Menu Control from DataBase


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/P...ontrolASP2.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").ConnectionS tring)
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">
<xsl:output 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>
Jun 13 '06 #1
0 4520

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cloverme | last post by:
Hi, I need help populating a listbox from a database on a webform. I created a an access database with a table, fields and data. Then I created a WebForm in vb.net and added a DropDownList...
1
by: John Hargrove | last post by:
I am building a database to manage test samples in an environmental laboratory. I am learning Access as I go and don't know much about the programming aspects. I hope to make the application...
2
by: Chris Barrow | last post by:
Hi everyone, Does anyone know if there is a problem populating a system.web.ui.htmlcontrols.htmlinputtext control when the control's type is set to "password?" I am attempting to retreive a...
6
by: Sandy | last post by:
Hello - I have a book that illustrates pulling menu items from a Sql Server table into an ascx via a stored procedure. Is this something that is done in the real world? I do like the effect...
2
by: MMA | last post by:
How do I populate the menu control in 2.0 from a database. I know this can be done with the Tree Control. Any code snippets? Thanks in advance.
1
by: Brad Isaacs | last post by:
want to know if you could please help me out in resolving an issue I am having regarding my Menu control. The ASP.NET Menu control requires extra work in order to access the database data, if...
8
by: Annalyzer | last post by:
I'm trying to populate a combo box on a form by inserting this query: SELECT * FROM menu WHERE NOT submitted; into the Row Source property of the combo box control. The Row Source Type is...
2
by: eihabisaac | last post by:
hi all im using C# with mysql i want to populate the menustrip items based on the select statement bellow i can select the items from the table and show them but how to popule the MenuStrip ...
14
by: Philth | last post by:
Hi there, I've essentially got a form with several drop down, each populated by columns in various tables. The populating bit works fine - the column rows appear as they should in the menu. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.