Try this:
public DataTable fnXMLToDataTable(string filePath)
{
DataTable table = new DataTable("XmlData");
try
{
using(Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Code", typeof(int));
table.ReadXml(stream);
return table;
}
}
catch (Exception ex)
{
return null;
}
}
Now call the function and pass XML file Path. Like:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = fnXMLToDataTable("MyFilePath")
if(dt!=null)
{
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Code";
DropDownList1.DataBind();
}
}
--Amit