Slide 14.5: The SortedList object
Slide 14.7: XML files (cont.)
Home

XML Files


We can bind an XML file to a list control. Here is an XML file named countries.xml. The following example binds a DataSet to a list control by taking the following steps:
  1. Import the System.Data namespace. We need this namespace to work with DataSet objects. Include the following directive at the top of a page:
      <%@ Import Namespace="System.Data" %>

demo_xml_radio1.aspx

Web
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Import Namespace="System.Data" %>
<script language="VB" runat="server">
 Sub Page_Load(s As Object, e As EventArgs) Handles Me.Load
  If Not Page.IsPostBack then
   dim mycountries = New DataSet
   mycountries.ReadXml( MapPath( "countries.xml" ) )
   rb.DataSource = mycountries
   rb.DataValueField = "value"
   rb.DataTextField = "text"
   rb.DataBind( )
  End If
 End Sub

 Sub DisplayMessage( s as Object,e As EventArgs )
  lbl1.text = "Your favorite country is: " & _
    rb.SelectedItem.Text
 End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" > 
 <body> 
  <form runat="server">
   <asp:RadioButtonList runat="server" AutoPostBack="True" 
     id="rb" OnSelectedIndexChanged="DisplayMessage" />
   <p><asp:label id="lbl1" runat="server" /></p>
  </form>
 </body>
</html>