ASP.NET Web Forms - XML Files
We can bind an XML file to a list control.
An XML File
Here is an XML file named "countries.xml":
View this XML file: countries.xml
Binding a DataSet to a List Control
First, import the "System.Data" namespace. We need this namespace to work with the DataSet object. Include the following directive at the top of the .aspx page:
Next, create a DataSet for the XML file and load the XML file into the DataSet when the page is first loaded:
To bind data to a RadioButtonList control, first create a RadioButtonList control in the .aspx page (without any asp:ListItem elements):
Then add the script to create the XML DataSet and bind the values from the XML DataSet to the RadioButtonList control:
We then add a subroutine that executes when a user clicks an item in the RadioButtonList control. When a radio button is clicked, a line of text appears in the label: