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!