|
Bind a DataSet to a List Control
|
|
At first, import the "System.Data" namespace and we need this namespace to work with DataSet objects.
For this,include the following directive at the top of an .aspx page:
|
|
<%@ Import Namespace="System.Data" %>
|
|
|
Next, create a DataSet for the XML file and when the page is first loaded,load the XML file into the DataSet:
|
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New DataSet
mycountries.ReadXml(MapPath("countries.xml"))
end if
end sub
|
|
|
First create a RadioButtonList control (without any asp:ListItem elements) in an .aspx page to bind the DataSet to a RadioButtonList control:
|
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" />
</form>
</body>
</html>
|
|
|
Then add the following script that builds the XML DataSet:
|
<%@ 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>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
</form>
</body>
</html>
|
|
|
Then in the RadioButtonList control,we add a sub routine to be executed when the user clicks on an item and when a radio button is clicked, a text will appear in a label:
|
<%@ 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>
<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>
|
|
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords:
ASP .NET using XML Files,
xml file using asp net,
asp web config,
asp web service,
xml web service,
xml tutorial,
c# using,
asp array,
c# xml,
xml examples,
upload files,
java xml,
xml example,
javascript xml,
xml sample,
asp example,
xml format,
asp function,
asp c#,
asp string,
asp code,
asp database,
asp javascript,
xml parsing,
html xml,
text xml,
asp application,
xml value,
c++ using,
xml name,
asp object,
xml parse