從XML文件中讀取數(shù)據(jù)綁定到DropDownList_.Net教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:C#定時(shí)器的使用
      C#定時(shí)器的使用 以下為引用的內(nèi)容: Timer timer1; this.timer1.Interval = 1000; this.timer1.Tick = new System.Ev

      1 、綁定DropDownList:

      以下為引用的內(nèi)容:
      ddl_language.DataSource = createDataSource();
      ddl_language.DataTextField = "languageTextField";
      ddl_language.DataValueField = "languageValueField";
      ddl_language.DataBind();

      2、上面用到的createDataSource()方法:

      以下為引用的內(nèi)容:
      private ICollection createDataSource()
      {
      //create a data table to store the data for the ddl_langauge control
      DataTable dt = new DataTable();

      //define the columns of the table
      dt.Columns.Add("languageTextField",typeof(string));
      dt.Columns.Add("languageValueField",typeof(string));

      //read the content of the xml file into a DataSet
      DataSet lanDS = new DataSet();
      string filePath = ConfigurationSettings.AppSettings["LanguageXmlFile"];
      lanDS.ReadXml(filePath);

      if(lanDS.Tables.Count > 0)
      {
      foreach(DataRow copyRow in lanDS.Tables[0].Rows)
      {
      dt.ImportRow(copyRow);
      }
      }

      DataView dv = new DataView(dt);

      return dv;
      }

      3、Web.config

      以下為引用的內(nèi)容:
      <appSettings>
      <!--The file path for the language type xml file-->
      <addkey="LanguageXmlFile"value="d:\Rhombussolution\Rhombus2\Languages.xml"/>
      </appSettings>

      4、Languages.xml

      以下為引用的內(nèi)容:

      <?xmlversion="1.0"encoding="utf-8"?>
      <languageTypes>
      <language>
      <languageValueField>en-US</languageValueField>
      <languageTextField>English</languageTextField>
      </language>
      <language>
      <languageValueField>zh-CN</languageValueField>
      <languageTextField>中文</languageTextField>
      </language>
      <language>
      <languageValueField>ja-JP</languageValueField>
      <languageTextField>日語</languageTextField>
      </language>
      </languageTypes>

      分享:.NET中加密與解密QueryString的方法
      1.加密。 Response.Redirect("DetailInfo.aspx?id=" Convert.ToBase64String (System.Text.Encoding.Default.GetBytes("sp10006")).Replace(" ","+"

      來源:模板無憂//所屬分類:.Net教程/更新時(shí)間:2008-08-22
      相關(guān).Net教程