Reprinted-read data from the XML file and bind it to dropdownlist

Source: Internet
Author: User

1. Bind dropdownlist:

Ddl_language.datasource = createdatasource ();
Ddl_language.datatextfield = "languagetextfield ";
Ddl_language.datavaluefield = "languagevaluefield ";
Ddl_language.databind ();

2. The createdatasource () method used above:

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 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

<Deleetask> <! -- The file path for the language type XML file --> <addkey = "languagexmlfile" value = "D: \ fig \ Fig 2 \ ages. xml"/> </FIG>

4. Ages. xml

<? Xmlversion = "1.0" encoding = "UTF-8"?> <Shortagetypes> <language> <shortagevaluefield> en-US </shortagevaluefield> <shortagetextfield> English </shortagetextfield> </language> <shortagevaluefield> ZH-CN

From: http://dev.csdn.net/author/guoshaohong/ee27abbe9e874a2f837d47d5916db4a4.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.