Hi,Here I am going to code you how to bind the
data from XML to any control in C# I have bind the data to listbox control from
XML file. In such a way we can bind it to DropdownList, Checkboxlist etc. XML file
should follow the even data as Shown below.
XML File :
<?xml version="1.0" encoding="utf-8" ?>
<TableNames>
<key id="001">
<value>Brinjal</value>
</key>
<key id="002">
<value>Potato</value>
</key>
<key id="003">
<value>tomato</value>
</key>
<key id="004">
<value>carrot</value>
</key>
<key id="005">
<value>Onion</value>
</key>
<key id="006">
<value>Beans</value>
</key>
<key id="007">
<value>Drum
Stick</value>
</key>
</TableNames>
ASPX Code
<html>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1"
runat="server"></asp:ListBox>
</div>
</form>
</body>
</html>
C# Code
string filePath = "D:\\Self
Practice\\Sol1\\Sol1\\XMLDATA.xml";
DataSet ds = new DataSet();
ds.ReadXml(filePath);
var dic = (from order
in ds.Tables[0].AsEnumerable()
select
new
{
UserView =
order.Field<String>("Value"),
DevView =
order.Field<String>("id")
}).AsEnumerable().ToDictionary(k => k.DevView, v => v.UserView);
ListBox1.DataSource = dic;
ListBox1.DataTextField = "Value";
ListBox1.DataValueField = "key";
ListBox1.DataBind();