Click to See Complete Forum and Search --> : Use XML to Populate Combo Box
leahayes00
01-19-2004, 06:36 PM
Hi,
I am using ASP.NET with VB.NET and XML.
I have the following XML file and would like to populate a drop-down list control (System.Web.UI.WebControls.DropDownList). I would like the <page> elements to be placed as the drop-down list items' text and the <url> element to become the drop-down list items' value.
<?xml version="1.0" encoding="ISO-8859-1"?>
<jumplist>
<jumpitem>
<page>Main Page</page>
<url></url>
</jumpitem>
<jumpitem>
<page>--------------</page>
<url></url>
</jumpitem>
<jumpitem>
<page>Forums Home</page>
<url>forum/forums.aspx</url>
</jumpitem>
<jumpitem>
<page>--------------</page>
<url></url>
</jumpitem>
<jumpitem>
<page>Gallery</page>
<url>gallery.aspx</url>
</jumpitem>
</jumplist>
Would somebody please be able to show me how to do this?
Regards,
Lea Hayes
Khalid Ali
01-19-2004, 10:25 PM
This resource have examples that read xml and create html out of it (http://www.webapplikations.com/pages/html_js/xml_js.html?menu_id=Web_sub)
Read this and see if yuo can make it work..if not then I'll try to help you(I don't know asp.net or anyother dot net,however I know how to parse xml to create html
lillu
02-09-2004, 04:10 AM
Hi there,
I'm just starting ASP.NET myself using VB.NET.
I haven't found exactly what you need but you may want to try and piece things together with these links.
http://www.aspfree.com/c/a/ASP-Code/Relational-DropDownList-Using-VBNET/ Relational DropDownList Using VB.NET
http://www.freevbcode.com/ShowCode.asp?ID=5214 Drop Down Color Picker (VB NET)
http://www.eggheadcafe.com/articles/20030605.asp A Generic Xml Dropdown Menu ServerControl
http://www.eggheadcafe.com/articles/cstovbweb/converter.aspx C# To VB .NET Source Code Converter
leahayes00
02-09-2004, 07:04 AM
Hi,
Thankyou for all of your help, I managed to create the following if anybody is interested, this was for a jump-list drop-down list control:
THE XML FILE "Jump List.xml":
<?xml version="1.0" encoding="ISO-8859-1"?>
<jumplist>
<jumpitem>
<page>Main Page</page>
<url></url>
</jumpitem>
<jumpitem>
<page> -------------------------</page>
<url></url>
</jumpitem>
<jumpitem>
<page>Forums Home</page>
<url>forum/forums.aspx</url>
</jumpitem>
<jumpitem>
<page> -------------------------</page>
<url></url>
</jumpitem>
<jumpitem>
<page>Gallery</page>
<url>gallery.aspx</url>
</jumpitem>
</jumplist>
THE IMPLEMENTATION CODE:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' don't continue if this is a post back!
If IsPostBack Then Exit Sub
' populate the jump-to drop-down list with jump-to locations
Dim datadoc As New DataSet
datadoc.ReadXml(GetServerPath() + "Jump List.xml")
Dim xmlDataDoc As New XmlDataDocument(datadoc)
Dim strXPathQuery As String = "/jumplist/jumpitem"
Dim nodeDetail As XmlNode
Dim itemText As String
Dim itemValue As String
For Each nodeDetail In xmlDataDoc.SelectNodes(strXPathQuery)
itemText = nodeDetail.ChildNodes(1).InnerText.ToString()
itemValue = nodeDetail.ChildNodes(0).InnerText.ToString()
lstJumpTo.Items.Add(New ListItem(itemValue, itemText))
Next
End Sub
Private Sub lstJumpTo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstJumpTo.SelectedIndexChanged
' if the selected item has a value then navigate to tha URL
If Not lstJumpTo.SelectedValue = "" Then
Response.Redirect(GetServerPath() & lstJumpTo.SelectedValue)
End If
End Sub
Public Function GetServerPath() As String
Dim RootPath As String = Request.ApplicationPath
If RootPath.Substring(RootPath.Length - 1, 1) = "/" Then
RootPath = RootPath.Substring(1, RootPath.Length - 1)
End If
Return Request.Url.GetLeftPart(UriPartial.Authority) + RootPath + "/"
End Function
Thanks again!
Best Regards,
Lea Hayes