Asp.net reads XML files and binds dropdownlist data

Source: Internet
Author: User
ASP page: Code
< ASP: dropdownlist ID = " Compacttype " Runat = " Server " Autocallback = " True " Width = " 153px " >   </ ASP: dropdownlist >

XML file Code
<? XML version = " 1.0 " Encoding = " UTF-8 "   ?>
< Roots >
< Root >
< ID > 1 </ ID >
< Culture > Below Junior High School </ Culture >
</ Root >
< Root >
< ID > 2 </ ID >
< Culture > Junior High School </ Culture >
</ Root >
< Root >
< ID > 3 </ ID >
< Culture > Technical Secondary School </ Culture >
</ Root >
< Root >
< ID > 4 </ ID >
< Culture > High School </ Culture >
</ Root >
< Root >
< ID > 5 </ ID >
< Culture > Junior college </ Culture >
</ Root >
< Root >
< ID > 6 </ ID >
< Culture > Bachelor </ Culture >
</ Root >
</ Roots >

<3> for details about how to read xmlwen, refer to the method for binding --- M.

Code
///   <Summary>
/// Read XML files, fill in dropdownlist with data, and bind them
///   </Summary>
///   <Param name = "path"> XML file path </Param>
///   <Param name = "DP"> Name of the dropdownlist to be bound </Param>
///   <Param name = "ID"> Dropdownlist text to be displayed (a node of the XML file) </Param>
///   <Param name = "Val"> Dropdownlist value to be displayed (a node of the XML file) </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 ();
}

<4> call Code
Securityfactory SF =   New Securityfactory ();
// XML file path
String Path2 = Server. mappath ( " ./XML/xmlfile2.xml " );
SF. readxml (path2,
This . Compacttype, " ID " , " Val " );

Bound successfully!

 

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.