- 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.
- 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" />
...
- 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( )
...
- 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