How to bind XML data to ASP.NET repeater control?

How to bind XML data to ASP.NET repeater control?

To present data from several data source ASP.NET introduced controls like datagrid, datalist & repeater. Compare to datagrid repeater is connection oriented & gives faster access to data. Inner logic of repeater is similar to pointer. During data bind for custom structure repeater control is very useful. In this example I created a demo app to display a XML file data in tabular shape using ASP.NET repeater control.

In the below example I have a employees.xml file which contains name, designation, company & salary of several employees. What I want is, I want to display these data in a HTML Table using ASP.NET repeater control. To achieve this in code-behind file “Default.aspx.vb” page_load event I am creating an instance of new DataSet as employeelog. Then using ReadXml() method I am assigning the XML file data to the DataSet employeelog. Later to bind these data in repeater control I pointed the repeater control DataSource to DataSet employeelog. Finally calling emplog.DataBind() to bind XML data.

Now in Default.aspx page I have my repeater control is with data. To show these data in particular table rows & columns here I used <%#Container.DataItem(“Respective Field Name”)%> inside ItemTemplate of repeater control. To make each data rows user friendly here with ItemTemplate I used AlternatingItemTemplate with background color #e8e8e8.


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
<title>How to bind XML data to ASP.NET repeater control?</title>
<form id="frmRepeater" runat="server">
<asp:Repeater id="emplog" runat="server">

<table border="1" width="100%">
<th>Employee Name</th>
<th>Monthly Salary</th>

<td><%#Container.DataItem("name")%> </td>
<td><%#Container.DataItem("designation")%> </td>
<td><%#Container.DataItem("company")%> </td>
<td><%#Container.DataItem("salary")%> </td>

<tr bgcolor="#e8e8e8">
<td><%#Container.DataItem("name")%> </td>
<td><%#Container.DataItem("designation")%> </td>
<td><%#Container.DataItem("company")%> </td>
<td><%#Container.DataItem("salary")%> </td>




Imports System.Data

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim employeelog = New DataSet
emplog.DataSource = employeelog
End If
End Sub
End Class


<?xml version="1.0" encoding="ISO-8859-1"?>
<name>Sujata Panigraphi</name>
<designation>Chief Business Officer</designation>
<name>Abhishek Srivastab</name>
<designation>Technical Head</designation>
<company>Cognizant Solution</company>
<name>Biswabhusan Panda</name>
<designation>Project Manager</designation>
<company>TATA Technology</company.
<name>Sunanda Patnayak</name>
<designation>Team Leader</designation>
<name>Raghav Roy</name>
<designation>Sr. UI Developer</designation>
<company>Persistent System</company>