ASP tutorial. NET reading XML documents and setting App_Data directory details
1. Not all resource files can be put into the App_Data folder
You cannot place resources such as pictures in the App_Data folder, and when you set up the TreeView and so on, the path is selected, the page is displayed, but the runtime does not show, and the changes were found only a long time.
Database tutorial files, XML files and other other can be placed in the App_Data;
DataSet bound to list control
First, import the "System.Data" namespace. We need this namespace to work with the DataSet object. Include the following instruction at the top of the. aspx page:
<%@ import namespace= "System.Data"%> Next, create a dataset for this XML file and load the XML file into the dataset when the page first loads:
<script runat= "Server" >
Sub Page_Load
If not Page.IsPostBack then
Dim mycountries=new DataSet
Mycountries.readxml (MapPath ("Countries.xml"))
End If
End Sub If you want to bind the dataset to the RadioButtonList control, first create a RadioButtonList control (without any asp:listitem elements) in the. aspx page:
<body>
<form runat= "Server" >
<asp:radiobuttonlist id= "RB" runat= "Server"
Autopostback= "true"/>
</form>
</body>
<%@ import namespace= "System.Data"%>
<script runat= "Server" >
Sub Page_Load
If not Page.IsPostBack then
Dim mycountries=new DataSet
Mycountries.readxml (MapPath ("Countries.xml"))
Rb.datasource=mycountries
rb.datavaluefield= "Value"
rb.datatextfield= "Text"
Rb.databind ()
End If
End Sub
</script>
<body>
<form runat= "Server" >
<asp:radiobuttonlist id= "RB" runat= "Server"
Autopostback= "true" onselectedindexchanged= "DisplayMessage"/>
</form>
</body>
<%@ import namespace= "System.Data"%>
<script runat= "Server" >
Sub Page_Load
If not Page.IsPostBack then
Dim mycountries=new DataSet
Mycountries.readxml (MapPath ("Countries.xml"))
Rb.datasource=mycountries
rb.datavaluefield= "Value"
rb.datatextfield= "Text"
Rb.databind ()
End If
End Sub
Sub DisplayMessage (S as object,e as EventArgs)
Lbl1.text= "Your favorite country is:" & Rb.selecteditem.text
End Sub
</script>
<body>
<form runat= "Server" >
<asp:radiobuttonlist id= "RB" runat= "Server"
Autopostback= "true" onselectedindexchanged= "DisplayMessage"/>
<p><asp:label id= "LBL1" runat= "Server"/></p>
</form>
</body>
Here is an XML file called "Countries.xml":
<?xml version= "1.0" encoding= "iso-8859-1"
<countries>
<country> <text>china</text>
<value>c</value>
</country>
<country>
<text>sweden</text>
<value>s</value>
</country>
<country>
<text>france</text>
<value>f</value>
</country>
<country>
<text>italy</text>
<value>i</value>
</country>
</countries>