WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

ASP.NET MVC - Publishing the Website


We can tie a XML document to a rundown control.


An XML File

Here is a XML document named "countries.xml":

<?xml version="1.0" encoding="ISO-8859-1"?>

<countries>

<country>
  <text>Norway</text>
  <value>N</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>

Take a gander at the XML document: countries.xml


Bind a DataSet to a List Control

First, import the "System.Data" namespace. We need this namespace to work with DataSet objects. Incorporate the following mandate at the highest point of an .aspx page:

<%@ Import Namespace="System.Data" %>

Next, make a DataSet for the XML document and burden the XML record into the DataSet when the page is first loaded:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  diminish mycountries=New DataSet
  mycountries.ReadXml(MapPath("countries.xml"))
end if
end sub

To tie the DataSet to a RadioButtonList control, first make a RadioButtonList control (without any asp:ListItem components) in an .aspx page:

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True"/>
</form>

</body>
</html>

Then include the content that constructs the XML DataSet:

<%@ Import Namespace="System.Data" %>

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  diminish mycountries=New DataSet
  mycountries.ReadXml(MapPath("countries.xml"))
  rb.DataSource=mycountries
  rb.DataValueField="value"
  rb.DataTextField="text"
  rb.DataBind()
end if
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage"/>
</form>

</body>
</html>

Then we add a sub routine to be executed when the client taps on a thing in the RadioButtonList control. At the point when a radio catch is clicked, a content will show up in a label:

Example

<%@ 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 most loved nation is: " & rb.SelectedItem.Text
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage"/>
<p><asp:label id="lbl1" runat="server"/></p>
</form>

</body>
</html>