Reference
Set the Default.aspx as startup page.
Database
I have made use of the following table Customers with the schema as follows.
I have already inserted few records in the table.
You can download database SQL from here.
HTML
ListView.apsx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta http-equiv="Refresh" content="5" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblTime" runat="server" Text=""></asp:Label>
<br />
<asp:ListView ID="lvCustomers" runat="server" GroupPlaceholderID="groupPlaceHolder1"
ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<th>
CustomerId
</th>
<th>
Name
</th>
<th>
Country
</th>
</tr>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<%# Eval("CustomerId") %>
</td>
<td>
<%# Eval("Name") %>
</td>
<td>
<%# Eval("Country") %>
</td>
</ItemTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
Namespaces
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
C#
ListView.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindListView();
}
lblTime.Text = "Last Refreshed : " + DateTime.Now.ToString();
}
private void BindListView()
{
string constr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT CustomerId, Name, Country FROM Customers";
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
lvCustomers.DataSource = dt;
lvCustomers.DataBind();
}
}
}
}
Default.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Update part of page periodically</title>
</head>
<body>
<form id="form1" runat="server">
<div>
This is the Main Page
<br />
<br />
<br />
<br />
<iframe id="frame1" src="ListView.aspx" frameborder="0" style="width: 493px; height: 295px">
</iframe>
</div>
</form>
</body>
</html>