Read XML and bind to RadioButtonList implementation ideas and demo animation _ Practical Skills

Source: Internet
Author: User
To read XML documents, you can use the ReadXml () method in the System.Data.DataSet category. As the following XML document, placed under the root directory of the site:
Yearofbirth.xml
Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<YearOfBirths>
<YearOfBirth>
<ID>1</ID>
<Name> mice </Name>
</YearOfBirth>
<YearOfBirth>
<ID>2</ID>
<Name> Cattle </Name>
</YearOfBirth>
<YearOfBirth>
<ID>3</ID>
<Name> Tiger </Name>
</YearOfBirth>
<YearOfBirth>
<ID>4</ID>
<Name> Rabbit </Name>
</YearOfBirth>
<YearOfBirth>
<ID>5</ID>
<Name> Dragon </Name>
</YearOfBirth>
<YearOfBirth>
<ID>6</ID>
<Name> Snake </Name>
</YearOfBirth>
<YearOfBirth>
<ID>7</ID>
<Name> Horse </Name>
</YearOfBirth>
<YearOfBirth>
<ID>8</ID>
<Name> Sheep </Name>
</YearOfBirth>
<YearOfBirth>
<ID>9</ID>
<Name> Monkey </Name>
</YearOfBirth>
<YearOfBirth>
<ID>10</ID>
<Name> Chicken </Name>
</YearOfBirth>
<YearOfBirth>
<ID>11</ID>
<Name> Dog </Name>
</YearOfBirth>
<YearOfBirth>
<ID>12</ID>
<Name> Pig </Name>
</YearOfBirth>
</YearOfBirths>

Use a property to get this document:
Copy Code code as follows:

private String XmlFile
{
Get
{
Return Server.MapPath ("~/yearofbirth.xml");
}
}

Pull a RadioButtonList control on the ASPX page to display the XML data.
Copy Code code as follows:

<asp:radiobuttonlist id= "Radiobuttonlistyearofbirth" runat= "Server" repeatcolumns= "6" repeatdirection= " Horizontal "></asp:RadioButtonList>

Next, use the dataset to read the properties of the XML file that you just wrote.
Copy Code code as follows:

View Code
Using System;
Using System.Collections.Generic;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
public partial class Default3:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
Data_binding ();
}
private void Data_binding ()
{
Using (DataSet ds = new DataSet ())
{
Ds. READXML (XmlFile);
This. Radiobuttonlistyearofbirth.datasource = ds;
This. Radiobuttonlistyearofbirth.datatextfield = "Name";
This. Radiobuttonlistyearofbirth.datavaluefield = "ID";
This. Radiobuttonlistyearofbirth.databind ();
}
}
}

Web page Run Effect:

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.