RepeaterControl.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RepeaterControl.aspx.cs" Inherits="RepeaterControl" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
//<% %> It is raser syntax
<table class="auto-style1">
<tr>
<td>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</td>
<td>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table border="1" width="250" height="250">
<tr>
<td>
<h3>ID</h3>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<h3>NAME</h3>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<h3>GENDER</h3>
</td>
<td>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("gender") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<h3>CITY</h3>
</td>
<td>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("city") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate>
<br />
</SeparatorTemplate>
</asp:Repeater>
</td>
</tr>
</table>
//Use Reapeater control code in gridview
<asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" ShowHeader="False">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table border="1" width="250" height="250">
<tr>
<td>
<h3>ID</h3>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<h3>NAME</h3>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<h3>GENDER</h3>
</td>
<td>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("gender") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<h3>CITY</h3>
</td>
<td>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("city") %>'></asp:Label>
</td>
</tr>
</table>
<br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</div>
</form>
</body>
</html>
RepeaterControl.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class RepeaterControl : System.Web.UI.Page
{
string cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = getData();
GridView1.DataSource = dt;
GridView1.DataBind();
GridView2.DataSource = dt;
GridView2.DataBind();
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
DataTable getData()
{
SqlConnection con = new SqlConnection(cs);
string query = "select * from Emp";
SqlDataAdapter sda = new SqlDataAdapter(query,con);
DataTable data = new DataTable();
sda.Fill(data);
return data;
}
}
0 Comments