- Online Barcode Generator
- How To
- Buy Now
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" ?>
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()
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:
ASP.NET AJAX UI Controls