asp.net - Populate a DropDownList from an XmlDataSource

Populating a DropDownList from XmlDataSource
Here I present a simple example, where I show how to bind XmlDataSource with DropDownList.

XmlDataSource
First create an Xml file name ValidationToolBoxControls.xml. The Xml file should place in App_Data folder. Here is the source code of ValidationToolBoxControls.xml file.
ValidationToolBoxControls.xml

<?xml version="1.0" encoding="utf-8" ?>
<ValidationToolBoxControl>
  <Control Name="RequiredFieldValidator" />
  <Control Name="RangeValidator" />
  <Control Name="RegularExpressionValidator" />
  <Control Name="CompareValidator" />
  <Control Name="CustomValidator" />
  <Control Name="ValidationSummary" />
</ValidationToolBoxControl>
Bind Xml Data with DropDownList
Now create a Web Form name DropDownListXmlDataSource.aspx. In this file add a XmlDataSource Control, a DropDownList Control and two Label Control. For XmlDataSource Control's DataFile property uses the ValidationToolBoxControls.xml file. And for DropDownList DataSourceID property use the XmlDataSource control's ID. Make sure the DropDownList's AutoPostBack property value is true. The theme is when someone select a option from DropDownList, the Label control show this Item. Here is the source code of DropDownListXmlDataSource.aspx file.
DropDownListXmlDataSource.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) {
        Label1.Text = "Your favorite Validation ToolBox Control is: <br/>" +
            DropDownList1.SelectedItem.Text.ToString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>DropDownList With XmlDataSource Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="HotPink" />
        <br /><br />
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/ValidationToolBoxControls.xml"></asp:XmlDataSource>
        <asp:Label ID="Label2" runat="server" Text="Choose favorote Control" AssociatedControlID="DropDownList1" />
        <asp:DropDownList
             ID="DropDownList1"
             runat="server"
             DataSourceID="XmlDataSource1"
             DataTextField="Name"
             OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
             AutoPostBack="true"
             BackColor="Bisque"
             >
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>
More asp.net examples