zoukankan      html  css  js  c++  java
  • .net 读取Xml文件并进行DropDownList数据绑定

    页面:

     <asp:DropDownList ID="compactType" runat="server" AutoCallBack="True" Width="153px"> </asp:DropDownList>

    xml:

    <?xml version="1.0" encoding="utf-8" ?>
    <roots>
    <root>
      
    <id>1</id>
      
    <Culture>初中以下</Culture>
    </root>
    <root>
      
    <id>2</id>
      
    <Culture>初中</Culture>
    </root>
    <root>
      
    <id>3</id>
      
    <Culture>中专</Culture>
    </root>
    <root>
      
    <id>4</id>
      
    <Culture>高中</Culture>
    </root>
    <root>
      
    <id>5</id>
      
    <Culture>大专</Culture>
    </root>
    <root>
      
    <id>6</id>
      
    <Culture>本科</Culture>
    </root>

    </ roots>

    c#后台:

    /// <summary>
      
    /// 读取xml文件,用数据填充DropDownList,进行绑定
      
    /// </summary>
      
    /// <param name="path">xml文件路径</param>
      
    /// <param name="dp">要进行绑定的DropDownList名称</param>
      
    /// <param name="id">DropDownList要显示的文本(xml文件的一个节点)</param>
      
    /// <param name="val">DropDownList要显示的值(xml文件的一个节点)</param>
      public void ReadXml(string path,DropDownList dp,string id,string val)
      {
        DataSet ds 
    = new DataSet();
        ds.ReadXml(path);
        dp.DataSource 
    = ds;     
        dp.DataTextField 
    = id ;
        dp.DataValueField 
    = val;
        dp.DataBind();     

      } 

    SecurityFactory sf = new SecurityFactory();
    string path2 = Server.MapPath("./xml/XMLFile2.xml");
    //xml文件路径
    sf.ReadXml(path2, 
    this.compactType, "id""val"); 
  • 相关阅读:
    网店推广之秘诀
    预言:“你被暴光了没有?” 将成为2010又一网络流行语
    已不联系好多年
    任道而重远
    从思南县看撤县建市对提升城市价值的影响
    我和三十有个约定
    浅谈小学生英语学习方法
    热烈祝贺IT诗人代腾飞官方网站开通啦
    爱情许愿砂
    “走远了” 2010又一网络流行语诞生
  • 原文地址:https://www.cnblogs.com/lizhao/p/1990472.html
Copyright © 2011-2022 走看看