Xml to DropDownList

Sample of xml file.

<?xml version=”1.0″ encoding=”utf-8″  ?>
<unitedstates>
    <state id=”AL” name=”AL – Alabama” />
</unitedstates>

ASP code

<asp:DropDownList ID=”ddlState” runat=”server” />

Code behind

XmlDataSource xml = new XmlDataSource();
xml.DataFile = Server.MapPath(“States.xml”);

ddlState.DataSource = xml;
ddlState.DataValueField = “id”;
ddlState.DataTextField = “name”;
ddlState.AppendDataBoundItems = true;
ddlState.DataBind();