web 2.0

ASP.NET(vb.net) & Repeater - XML

ASP.NET(vb.net) & Repeater - XML Example scripts how to use Repeater control in asp.net , Binding the datasource (XML) to FormView control.

ShotDev Focus:
- ASP.NET(vb.net) & Repeater - XML

customer.xml


<?xml version="1.0" encoding="UTF-8"?>
<mydatabase>
<customer>
<CustomerID>C001</CustomerID>
<Name>Win Weerachai</Name>
<Email>win.weerachai@shotdev.com</Email>
<CountryCode>TH</CountryCode>
<Budget>1000000</Budget>
<Used>600000</Used>
</customer>
<customer>
<CustomerID>C002</CustomerID>
<Name>Jake Sully</Name>
<Email>jake.sully@shotdev.com</Email>
<CountryCode>EN</CountryCode>
<Budget>2000000</Budget>
<Used>800000</Used>
</customer>
<customer>
<CustomerID>C003</CustomerID>
<Name>Tony Stark</Name>
<Email>tony.stark@shotdev.com</Email>
<CountryCode>US</CountryCode>
<Budget>3000000</Budget>
<Used>600000</Used>
</customer>
<customer>
<CustomerID>C004</CustomerID>
<Name>Peter Parker</Name>
<Email>peter.parker@shotdev.com</Email>
<CountryCode>US</CountryCode>
<Budget>4000000</Budget>
<Used>100000</Used>
</customer>
</mydatabase>

Example

RepeaterReadXML.aspx

<%@ Import Namespace="System.Data"%>
<%@ Page Language="VB" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
Dim ds As New DataSet
ds.ReadXml(MapPath("customer.xml"))

'*** BindData to Repeater ***'
myRepeater.DataSource = ds
myRepeater.DataBind()

End Sub

</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater id="myRepeater" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th>CustomerID</th>
<th>Name</th>
<th>Email</th>
<th>CountryCode</th>
<th>Budget</th>
<th>Used</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center"><%#Container.DataItem("CustomerID") %></td>
<td><%#Container.DataItem("Name") %></td>
<td><%#Container.DataItem("Email") %></td>
<td align="center"><%#Container.DataItem("CountryCode") %></td>
<td align="right"><%#Container.DataItem("Budget") %></td>
<td align="right"><%#Container.DataItem("Used") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<!--
<tr>
<th>CustomerID</th>
<th>Name</th>
<th>Email</th>
<th>CountryCode</th>
<th>Budget</th>
<th>Used</th>
</tr>
-->
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>

Create a asp.net file and save to path root-path/dotnet/

Run
http://localhost/dotnet/RepeaterReadXML.aspx

Screenshot

ASP.NET(vb.net) & Repeater - XML
.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.