ASP. NET-XML file bound to list

Source: Internet
Author: User
Countries. xml

<? XML version = "1.0" encoding = "ISO-8859-1"?>

<Countries>

<Country>
<Text> China </text>
<Value> C </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>

Bind dataset to the list control catalog -------------------------------------------------------------------------------------
First, import the "system. Data" namespace. We need the namespace to work with the DataSet object. Include the following command at the top of the. ASPX page.
Load the XML file into dataset when the page is first loaded.
Create a radiobuttonlist control on the. ASPX page (without any ASP: listitem element ).
Add a subroutine that is executed when you click the project in the radiobuttonlist control. When you click a single-choice button, a text will appear in the label.

<% @ 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>

<HTML>
<Body>

<Form runat = "server">
<Asp: radiobuttonlist id = "rb" runat = "server"
Autopostback = "true" onselectedindexchanged = "displaymessage"/>
<P> <asp: Label id = "lbl1" runat = "server"/> </P>
</Form>

</Body>
</Html>

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.