Repeater Control In ASP.NET Web Forms | ASP.NET Repeater Control | Learn ASP.NET
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;
namespace REPEATER_CONTROL
{
public partial class WebForm1 : 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();
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;
}
}
}
Above File is REPEATER_CONTROL\WebForm1.aspx.cs
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="REPEATER_CONTROL.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 344px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server" GridLines="None" ShowHeader="False">
<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>
</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>
</div>
</form>
</body>
</html>
Comments
Post a Comment