ASP.NET(vb.net) & XmlDataSource - asp:XmlDataSource - The XmlDataSource represents an XML data source to data-bound controls.
ShotDev Focus:
- ASP.NET(vb.net) & XmlDataSource - asp:XmlDataSource
Tag Control :
<asp:XmlDataSource ID="XmlDataSource1" runat="server"></asp:XmlDataSource>
Drag XmlDataSource Control to ASP.NET Web Form. on XmlDataSource Tasks -> Configure Data Source.
Browse a XML File
Select XML File.
customer.xml
<?xml version="1.0" encoding="UTF-8"?> <mydatabase> <customer Name="Win Weerachai"> </customer> <customer Name="Jake Sully"> </customer> <customer Name="Tony Stark"> </customer> <customer Name="Peter Parker"> </customer> </mydatabase>
Data file and XPath expression
Drag DropDownList Control to ASP.NET Web Form . On DropDownList Tasks -> Choose Data Source...
Select a data source XmlDataSource, Select a data field to display in the DropDownList , Select a data field for the value of the DropDownList.
Example Code
Default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>ShotDev.Com Tutorial</title> </head> <body> <form id="form1" runat="server"> <div> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/customer.xml" XPath="mydatabase/customer"></asp:XmlDataSource> <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="XmlDataSource1" DataTextField="Name" DataValueField="Name"> </asp:DropDownList> </div> </form> </body> </html>
Default.aspx.vb
Partial Class _Default Inherits System.Web.UI.Page End Class
Screenshot