How to Bind a XML File to a Dropdownlist Control

Microsoft's Active Server Pages for the .Net platform (ASP.Net) allows you to create interactive web pages using the feature-rich Visual Studio development platform. An example of an interactive web page is one that features a "DropDownList" control. This control allows users to click on it and select an item from a list. The items in the list can are populated using XML files, which are very common data exchange files for Internet applications.

Things You'll Need

  • Windows PC with Visual Studio 2010 installed
Show More

Instructions

    • 1

      Click on the Visual Studio 2010 icon to launch the application. From the main menu, select "File," "Project" and then "New." A "New Project Wizard" window appears. Select "C#" in the left-hand column and select "ASP.Net Web Application" in the other column. Press the "OK" button to create the project. A new project is created and a source code file appears in the main editor window.

    • 2

      Locate the "Solution Explorer," which is on the left-hand side of the main editor window. Right-click on your project and select "Add" and "New Item" from the menus that appear. The "Add New Item" window appears.

    • 3

      Select "Data" from the left-hand column and "XML File" from the right-hand column. Press the "OK" button to add the XML file to your project. An XML file appears in the main editor window. Add the following text to the file:

      <root>

      <node>"one"</node>

      <node>"two"</node>

      </root>

    • 4

      Click on the "Design" tab located at the bottom of the source code file editor. The source code file disappears and a view of the ASP.Net web page appears. This page appears in a visual editor that you can drag and drop elements into.

    • 5

      Locate the "Toolbox" panel, which is to the right of the visual editor, and select "DropDownList." Click and drag it anywhere on the web page in the visual editor. When you release the mouse button, the "DropDownList" control is placed on the page.

    • 6

      Click on the right-facing arrow in the upper-right-hand corner of the "DropDownList" control. A menu appears.

    • 7

      Select "Choose Data Source" from the menu. A dialogue box entitled "Data Source Configuration Wizard" appears.

    • 8

      Click on the drop-down box located under the heading labeled "Select a data source:" and select "New Data Source." A list of several different data source types appears.

    • 9

      Select "XML" file from the list of data source types. Press the "OK" button to proceed. A "Configure Data Source" dialogue box appears.

    • 10

      Click on the button entitled "Browse" under the heading "Data File" to open a file explorer. Navigate to the location of your XML file and press "Open" to bind this file to the "DropDownList" control. The default folder that the file explorer opens should have the XML right inside of it, since it was added to the project in an earlier step.

    • 11

      Click the "OK" button on the "Configure Data Source" dialogue box to close it and save your settings.

    • 12

      Click the "OK" button on the "Data Source Configuration Wizard" to close it and save your settings.

    • 13

      Press the green "Play" button to launch the web application. A web browser opens and displays your ASP.Net web page. Click on the drop down box and see your items displayed.

Related Searches:

References

Comments

Related Ads

Featured