XMLDataSource is a control, which has the ability to get the XML from the XMLfile and wrap it inside the control.
Let us see how we can sue XMLDataSource in our application.
Building XML File :
First thing we need to do is to build an xml file to use it as a XMLDataSource
<?xml version="1.0" encoding="utf-8" ?>
<Items name="Credit Card"></Items>
<Items name="Debit Card"></Items>
<Items name="CD Player"></Items>
Please name this xml file as "Sample.xml"
Adding XMLDataSource control in aspx Page:
In the aspx page, add the XmlDataSource control and set the DataFile to the path where you have stored the Sample.xml file
In this example, i have stored the xml file in the path "/App_Data/Sample.xml"
After setting the path for the datafile,
i'm binding the values in the Sample.xml file into the CheckboxList control by setting the DataSourceID to the ID of the XMLDataSource
I have designed the aspx page using the below code samples
<title>XMLDataSource - Sample</title>
<form id="form1" runat="server">
<asp:XmlDataSource ID="MyXmlDataSource" runat="server" DataFile="/App_Data/Sample.xml">
<b>Please select the things you Own !</b>
<br /><br /><br />
<asp:CheckBoxList ID="ThingsOwn" runat="server" DataSourceID="MyXmlDataSource" DataMember="Items" DataTextField="Name"
Now it's almost done, I have just set the DataMember and DataTextField for the CheckBoxList.
Execute the page to see the XML Content populated as the Text in the CheckBoxListControl.
Its a helpful script