$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
ComboBox Data Binding with XML in ASP.NET
Home > How to > ComboBox Data Binding XML

Information for Data Binding from XML to ComboBox

The asp.net ComboBox Control allows users to display a list of pre-defined values from other data sources to target combobox objects. And from this online tutorial, we will show you how to acquire data from xml file and display it in the drop-down list of combobox by calling the DataBind method.
One thing that needs to be noted here is that, the format of target xml file which you are going to bind data from must have a specific structure. To be first, the xml file must has a single root which starts with a <Items> tag and ends up with a </Items> tag. Besides, the child nodes contained in the xml file should be represented with the <Item></Item> tag. In addition, if you are also allowed to add item properties to individual XML chide nodes as attributes. For instance, in following xml format example, we use Select property in the xml child node.
To help you have a better understanding of above requirements for the xml format, we here specifically display the content of a standard xml file as an example to illustrate required xml file structure.


<?xml version="1.0" encoding="utf-8" ?> 
<Item Text="A" Value="15" Selected="true" />
<Item Text="B" Value="14" />
<Item Text="C" Value="18" />
<Item Text="D" Value="9" />
<Item Text="E" Value="17" />
<Item Text="F" Value="12" />
<Item Text="G" Value="11" />
<Item Text="H" Value="19" />
<Item Text="I" Value="6" />
<Item Text="J" Value="3" />
<Item Text="K" Value="13" />
<Item Text="L" Value="10" />
<Item Text="M" Value="16" />
<Item Text="N" Value="1" />
<Item Text="O" Value="4" />
<Item Text="P" Value="2" />
<Item Text="Q" Value="8" />
<Item Text="R" Value="7" />
<Item Text="S" Value="5" />
<Item Text="T" Value="20" />

How to Bind Data from XML File to ComboBox

Since the xml file has created in our required format, now it is time to show you how to load data from the xml file and bind it to the target asp.net combobox object. In this example of binding data from xml file to combobox, we will mainly illustrate how to load data from an XML file to the web ComboBox Control.
To load data from an xml string into combobox object, we need to call the LoadXml method. And following C# code is provided for you to bind data from an xml string to combobox object.
private void BindComboBox()
string path = "combobox.xml";

StreamReader sr = new StreamReader(Server.MapPath(path));

//load items from XML string

private void Page_Load(object sender, System.EventArgs e)
if (!Page.IsPostBack)
And following image is presented here to demonstrate the result of loading data from an xml string into a combobox object using ASP.NET AJAX. If you have met any problem in the data binding process, please feel free to contact us via E-mail.

Other Related ComboBox Data Binding Tutorials

Apart from the function to bind data from XML file to combobox, the asp.net ComboBox Control also allows developers to bind combobox to other data types, like: