Slide 14.6: XML files
Slide 14.8: The Repeater control
Home

XML Files (Cont.)

  1. Next, create a DataSet for the XML file and load the XML file into the DataSet by using the method ReadXml when the page is first loaded:
     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" ) )
         ...
    where the method MapPath retrieves the physical path that a virtual path, either absolute or relative, maps to.

  2. To bind the DataSet to a RadioButtonList, first create a RadioButtonList control (without any ListItem elements) in an .aspx page:
     <form runat="server">
       ...
       <asp:RadioButtonList id="rb" runat="server"
         AutoPostBack="True" />
       ...
  3. Then add the script that builds the XML DataSet:
       ...
       mycountries.ReadXml( MapPath( "countries.xml" ) )
       rb.DataSource     = mycountries
       rb.DataValueField = "value"
       rb.DataTextField  = "text"
       rb.DataBind( )
       ...
  4. Finally, add a sub routine DisplayMessage to be executed when the user clicks on an item in the RadioButtonList control. When a radio button is clicked, a text will appear in a label.
     Sub DisplayMessage( s as Object,e As EventArgs )
       lbl1.text = "Your favorite country is: " & _
         rb.SelectedItem.Text
     End Sub