0

I want bind a xml file to my DropDownList and I want use the xmlDataSource control.

Here is my ascx code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SearchControl.ascx.cs" Inherits="Telefonie.SearchControl" %>

    <div>
        <asp:Label runat="server" ID="lblSearch">Suchbegriff</asp:Label>
        <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
        <asp:Label runat="server" ID="lblLocation">Werk</asp:Label>
        <asp:DropDownList ID="LocationDropDown" runat="server">
        </asp:DropDownList>
        <asp:Button ID="btnSearch" runat="server" Text="Suchen" 
            onclick="btnSearch_Click" />
        <asp:XmlDataSource ID="LocationDataSource" runat="server" DataFile="~/App_Data/Werke.xml"></asp:XmlDataSource>
    </div>

Here is my xml file (this xml file is in app_data folder)

<?xml version="1.0" standalone="yes" ?>
<NewDataSet>
  <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="resources">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="Werk" type="xs:string" minOccurs="0" />        
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <resources>
    <Werk>Keine Angabe</Werk>
  </resources>
  <resources>
    <Werk>Germany</Werk>  
  </resources>
  <resources>
    <Werk>Other</Werk>
  </resources>
</NewDataSet>

I want that my DropDownList fill with this xml file but ho I can do this?

1

1 Answer 1

1
<asp:XmlDataSource ID="databasesSource" runat="server" XPath="/NewDataSet/resources" />
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
       databasesSource.Data = [your xml];
       databasesSource.DataBind();
    }
}         
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.