Aspx: </ ASP: checkboxlist >
< ASP: dropdownlist ID = "DDL" Runat = "Server" >
</ ASP: dropdownlist >
CS: Dataset DS = New Dataset ();
String Xmlpath = Server. mappath ( " ~ / " ) + " Ipusrtest/QQ. xml " ;
DS. readxml (xmlpath );
DDL. datatextfield = " Name " ;
DDL. datavaluefield = " Value " ;
DDL. datasource = DS;
DDL. databind ();
XML: <? XML version = "1.0" encoding = "UTF-8" ?>
< Prj >
< Two Value = "1" Name = "Single battery" />
< Two Value = "2" Name = "Combined battery" />
< Two Value = "3" Name = "Charger" />
< Two Value = "4" Name = "Mobile power" />
</ Prj >
Usage class: The method for reading XML data to dataset is:
# Region getdatasetbyxml
/// < Summary >
/// Read XML and return dataset directly
/// </ Summary >
/// < Param Name = "Strxmlpath" > XML file relative path </ Param >
/// < Returns > </ Returns >
Public static dataset getdatasetbyxml (string strxmlpath)
{< br> try
{< br> dataset DS = new dataset ();
// read XML to dataset
DS. readxml (getxmlfullpath (strxmlpath);
If (Ds. tables. count> 0)
{< br> return Ds;
}< br> return NULL;
}< br> catch (exception)
{< br> return NULL;
}< BR ># endregion