. NET Getting Started Tutorial: ASP. NET Parse XML file

Source: Internet
Author: User

. 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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.