• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    读取XML并绑定至RadioButtonList实现思路及演示动画
    读取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();
    }
    }
    }

    网页运行效果:
    您可能感兴趣的文章:
    • javascript判断是否有对RadioButtonList选项选择
    • ASP.NET jQuery 实例16 通过控件CustomValidator验证RadioButtonList
    • javascript RadioButtonList获取选中值
    • RadioButtonList绑定图片及泛型Dictionary应用
    上一篇:密码绑定至密码文本框中(TextMode设为Password)
    下一篇:CheckBox为CheckBoxList实现全选或全取消选择(js代码实现)
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    读取XML并绑定至RadioButtonList实现思路及演示动画 读取,XML,并,绑定,至,RadioButtonList,