讀取XML并綁定至RadioButtonList實(shí)現(xiàn)思路及演示動(dòng)畫(huà)
YearOfBirth.xml
<?xml version="1.0" encoding="utf-8" ?>
<YearOfBirths>
<YearOfBirth>
<ID>1</ID>
<Name>鼠</Name>
</YearOfBirth>
<YearOfBirth>
<ID>2</ID>
<Name>牛</Name>
</YearOfBirth>
<YearOfBirth>
<ID>3</ID>
<Name>虎</Name>
</YearOfBirth>
<YearOfBirth>
<ID>4</ID>
<Name>兔</Name>
</YearOfBirth>
<YearOfBirth>
<ID>5</ID>
<Name>龍</Name>
</YearOfBirth>
<YearOfBirth>
<ID>6</ID>
<Name>蛇</Name>
</YearOfBirth>
<YearOfBirth>
<ID>7</ID>
<Name>馬</Name>
</YearOfBirth>
<YearOfBirth>
<ID>8</ID>
<Name>羊</Name>
</YearOfBirth>
<YearOfBirth>
<ID>9</ID>
<Name>猴</Name>
</YearOfBirth>
<YearOfBirth>
<ID>10</ID>
<Name>雞</Name>
</YearOfBirth>
<YearOfBirth>
<ID>11</ID>
<Name>狗</Name>
</YearOfBirth>
<YearOfBirth>
<ID>12</ID>
<Name>豬</Name>
</YearOfBirth>
</YearOfBirths>
使用一個(gè)屬性來(lái)獲取這個(gè)文檔:
private string XmlFile
{
get
{
return Server.MapPath("~/YearOfBirth.xml");
}
}
在aspx網(wǎng)頁(yè)上拉一個(gè)RadioButtonList控件,用來(lái)顯示XML的數(shù)據(jù)。
<asp:RadioButtonList ID="RadioButtonListYearOfBirth" runat="server" RepeatColumns="6" RepeatDirection="Horizontal"></asp:RadioButtonList>
接下來(lái),用DataSet去讀取剛才寫(xiě)好的獲取XML文件的屬性。
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();
}
}
}
網(wǎng)頁(yè)運(yùn)行效果:

相關(guān)文章
.Net Web Api中利用FluentValidate進(jìn)行參數(shù)驗(yàn)證的方法
最近在做Web API,用到了流式驗(yàn)證,就簡(jiǎn)單的說(shuō)說(shuō)這個(gè)流式驗(yàn)證,下面這篇文章主要給大家介紹了關(guān)于.Net Web Api中利用FluentValidate進(jìn)行參數(shù)驗(yàn)證的相關(guān)資料,,需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07.net WINFORM的GDI雙緩沖的實(shí)現(xiàn)方法
下面小編就為大家分享一篇.net WINFORM的GDI雙緩沖的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12使用ASP.NET一般處理程序或WebService返回JSON的實(shí)現(xiàn)代碼
今天, 將為大家說(shuō)明如何在 ASP.NET 中使用一般處理程序或者 WebService 向 javascript 返回 JSON2011-10-10asp.net實(shí)現(xiàn)上傳圖片時(shí)判斷圖片的模式GRB或CMYK的方法
這篇文章主要介紹了asp.net實(shí)現(xiàn)上傳圖片時(shí)判斷圖片的模式GRB或CMYK的方法,涉及asp.net針對(duì)圖片的讀取及屬性操作相關(guān)技巧,需要的朋友可以參考下2016-07-07ASP.NET開(kāi)源導(dǎo)入導(dǎo)出庫(kù)Magicodes.IE完成Csv導(dǎo)入導(dǎo)出的方法
這篇文章主要介紹了ASP.NET開(kāi)源導(dǎo)入導(dǎo)出庫(kù)Magicodes.IE完成Csv導(dǎo)入導(dǎo)出的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06ASP.NET怎么操作DataTable實(shí)例應(yīng)用
有機(jī)會(huì)在博客園的博問(wèn)頻道上看到一個(gè)問(wèn)題,《ASP.NET怎么操作DataTable》;需要的朋友可以參考下2012-11-11Razor TagHelper實(shí)現(xiàn)Markdown轉(zhuǎn)HTML的方法
下面小編就為大家分享一篇Razor TagHelper實(shí)現(xiàn)Markdown轉(zhuǎn)HTML的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12asp.net MVC 在Controller控制器中實(shí)現(xiàn)驗(yàn)證碼輸出功能
這篇文章主要介紹了asp.net MVC 在Controller控制器中實(shí)現(xiàn)驗(yàn)證碼輸出功能,本文給大家介紹非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12在dropDownList中實(shí)現(xiàn)既能輸入一個(gè)新值又能實(shí)現(xiàn)下拉選的代碼
在dropDownList中實(shí)現(xiàn)既能輸入一個(gè)新值,又能實(shí)現(xiàn)下拉選項(xiàng),想必很多的朋友已經(jīng)為此功能按耐不住了吧,接下來(lái)與大家分享下如何實(shí)現(xiàn),感興趣的朋友可以參考下哈2013-04-04