第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

讀取XML并綁定至RadioButtonList

標(biāo)簽:
Java

读取XML的文档,可以使用System.Data.DataSet类别中的ReadXml()方法。如下面的xml文档,放在站点的根目录之下:

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>


使用一个属性来获取这个文档:

复制代码

 private string XmlFile    {        get        {            return Server.MapPath("~/YearOfBirth.xml");        }    }

复制代码


在aspx网页上拉一个RadioButtonList控件,用来显示XML的数据。

<asp:RadioButtonList ID="RadioButtonListYearOfBirth" runat="server" RepeatColumns="6" RepeatDirection="Horizontal"></asp:RadioButtonList>


接下来,用DataSet去读取刚才写好的获取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();        }    }}


网页运行效果:

 

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報(bào)

0/150
提交
取消