The Repeater control is used to display a repeated list of items that are bound to the control. The Repeater control may be bound to a database table, an XML file, or another list of items. Here we will show how to bind an XML file to a Repeater control.
Lets explain :
Client side --- Reapeterexample.aspx :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Reapeterexample.aspx.cs" Inherits="Reapeterexample" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater runat="server" ID="rpt1">
<HeaderTemplate>
<table border="1" style="border-collapse: collapse; font-family: Verdana; font-size: 12px;
width: 80%">
<tr style="font-size: 12px; color: White; font-weight: bold; font-family: Verdana, Helvetica, sans-serif;
background-color: #336699; height: 20px;">
<td align="center">
Client Code
</td>
<td align="center">
Client Name
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("ClientId")%>
</td>
<td>
<%# Eval("ClientName")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
Code behind side -----
Client side --- Reapeterexample.aspx .cs :
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("ClientId");
dt.Columns.Add("ClientName");
for (int i = 0; i < 10; i++)
{
DataRow dr = dt.NewRow();
dr["ClientId"] = i;
dr["ClientName"] = "ClientName-" + i;
dt.Rows.Add(dr);
rpt1.DataSource = dt;
rpt1.DataBind();
}
}
Output:
If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website
0 comments:
Post a Comment