. NET Getting Started Tutorial: ASP. NET Parse XML file
We can combine an XML file into Inventory Control.
Example
<%@ Import namespace= "System.Data"%>
<script runat= "Server" >
Sub Page_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>
<body>
<form runat= "Server" >
<asp:radiobuttonlist id= "RB" runat= "Server"
autopostback= "True" onselectedindexchanged= "DisplayMessage"/>
<p><asp:label id= "LBL1" runat= "Server"/></p>
</form>
</body>
< ml>
An XML file
This is an XML file named "Countries.xml":
<?xml version= "1.0" encoding= "Iso-8859-1"?>
<countries>
<country>
<text>Norway</text>
<value>N</value>
</country>
<country>
<text>Sweden</text>
<value>S</value>
</country>
<country>
<text>France</text>
<value>F</value>
</country>
<country>
<text>Italy</text>
<value>I</value>
</country>
</countries>
A dataset is bound to the control list first, the imported "System.Data" namespace. We need this kind of naming and DataSet object. Include one of the following directives. ASPX pages: <%@ Import namespace= "System.Data"%> Next, create a dataset XML file and load the XML file into the DataSet page first: <script runat= " Server >
Sub Page_Load
If not Page.IsPostBack then
Dim mycountries=new DataSet
Mycountries. READXML (MapPath ("Countries.xml"))
End If
The End Sub binds the data to the RadioButtonList control, first creating a RadioButtonList control (without any asp:listitem elements). ASPX page:<body><form runat= "Server" >
<asp:radiobuttonlist id= "RB" runat= "Server"
autopostback= "True"/></form></body>
Sub Page_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
</script><body><form runat= "Server" >
<asp:radiobuttonlist id= "RB" runat= "Server"
autopostback= "True" onselectedindexchanged= "DisplayMessage"/>
</form></body>
Sub Page_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 SubSub DisplayMessage (s as object,e as EventArgs)
lbl1.text= "Your Favorite country is:" & RB. Selecteditem.text
End Sub
</script><body><form runat= "Server" >
<asp:radiobuttonlist id= "RB" runat= "Server"
autopostback= "True" onselectedindexchanged= "DisplayMessage"/>
<p><asp:label id= "LBL1" runat= "Server"/></p>
</form></body>