asp.net read XML documents and set App_Data directory details

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.