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

From the previous user manuals that you have provided, you might now already know that Kettic ListBox DLL component supports data binding with data source like SqlDataSource, LinqDataSource, etc. Moreover, in this guiding page, we will provide you with detailed guidance as well as complete sample codes for listbox data binding with XML.
XML, abbreviated from Extensible Markup Language, as the name suggests, is a markup language that can be easily read with both human eyes and machines. It defines a set of rules and is widely used for encoding documents in a variety of scenarios.
In the following sections, we provides two methods for you to either bind a listbox to XML data source or directly bind to an XML file by loading it with simply a few lines of Visual C# .NET programming.

Binding ListBox from XML DataSource

In this section, we will provide you with a simple demo for selecting an XML for listbox data source, please follow the procedure step by step to see how this works out.
  1. Click the PerListBox Smart Tag and select "New Data Source" for the "Choose Data Source" drop down list, as has been illustrated in the screenshot below.
  2. Now that a wizard pops up, please go to the "Choose a data source type" page to select "XML File" and then click "OK" to proceed, as shown in the image below.
  3. Now it is time to "Configure Data Source", please use the Browse button to locate and select the target XML file. After that, click "OK" to proceed.
  4. Now here comes the last step to set set DataSourceID for the XMLDataSource1 for data binding with a few Visual C# .NET codes.
PerListBox.DataSourceID = "XmlDataSource1";
PerListBox.DataBind();

Binding ListBox from XML File

If you do not like Kettic ListBox data binding by selecting DataSource, you can opt for Plan B to directly load and import an XML file from your local disk with just a few lines of Visual C# .NET programming codes.
The demo codes below indicate how you can load an XML file named ListBox.xml from your local file for data binding.
string xmlText = File.ReadAllText(
Server.MapPath("ListBox.xml"));

PerListBox1.LoadXml(xmlText);
Please keep in mind that in order for both of the methods above to work, you need to have an XML file in advance which conforms to the format below:
<?xml version="1.0" encoding="utf-8" ?> 
<Items>
<Item Text="Amsterdam" Value="15" />
<Item Text="Barcelona" Value="14" />
<Item Text="Bonn" Value="18" />
<Item Text="Boston" Value="9" />
<Item Text="Brussels" Value="17" Selected="true" />
<Item Text="Dallas" Value="12" />
<Item Text="Denver" Value="11" />
<Item Text="Dublin" Value="19" />
<Item Text="Liverpool" Value="6" />
<Item Text="London" Value="3" />
<Item Text="Madrid" Value="13" />
<Item Text="Miami" Value="10" />
<Item Text="Moscow" Value="16" />
<Item Text="New York" Value="1" />
<Item Text="Oslo" Value="4" />
<Item Text="Paris" Value="2" />
<Item Text="San Francisco" Value="8" />
<Item Text="Seattle" Value="7" />
<Item Text="Sofia" Value="5" />
<Item Text="St.Paul" Value="20" />
</Items>
Let's take a look at how this works out. Below is a simple screenshot of ListBox after binding to an XML file.
ASP.NET AJAX UI Controls