Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
<?xml version="1.0" encoding="utf-8" ?>
<consumers>
  <consumer ID="1" Name="Pravin">
    <MeterNumber>9611186466</MeterNumber>
    <Address>Jayanagar 7th block</Address>
    <DCUName>DCUCMTRXXX00011</DCUName>
  </consumer>
  <consumer ID="2" Name="Praveen">
    <MeterNumber>9611186466</MeterNumber>
    <Address>Jayanagar 5th block</Address>
    <DCUName>SPPLCMTRXXX00031</DCUName>
  </consumer>
</consumers>
Posted

It is a super simple task, this is one of possible approaches:

XML
<asp:DropDownList ID="DropDownList1" runat="server"
        DataSourceID="XmlDataSource1" DataTextField="Name" DataValueField="ID">
</asp:DropDownList>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/test.xml"
        XPath="consumers/consumer"></asp:XmlDataSource>



Copy this code in a page and make sure that your file is called test.xml and that it is in the site root directory.


Cheers
 
Share this answer
 
Heres another way,

XmlDocument doc = new XmlDocument();
string path = Server.MapPath("~/test.xml");//path of xml file that you need to fetch values.
doc.Load(path);
DataSet _ds = new DataSet();
_ds.ReadXml(path);
yourdropdown.DataSource = _ds.Tables[0];
yourdropdown.datatextfield="ID";
yourdropdown.datavaluefield="Name";
yourdropdown.DataBind();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900