Tuesday, 14 May 2013

Repeater Control


Repeater Control have 5 entity which you can say templates.
1. Header Template  2. Item Template  3. AlternatingItemTemplate  4. Seperator Template  5. Footer Template
1. ItemTemplate: ItemTemplate defines how the each item is rendered from data source.
2. AlternatingItemTemplate: AlternatingItemTemplates is used to change the styles of Alternate Items in Data Source collection
3. Header Template: Header Template is used for Header text for Data Source collection and apply styles for header text.
4. Footer Template: Footer Template is used to display footer element for Data Source collection.
5. SeparatorTemplate: SeparatorTemplate will determine separator element which separates each Item in Item collection.

Design View:

01<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
02 
03<!DOCTYPE html>
04 
05<html xmlns="http://www.w3.org/1999/xhtml">
06<head runat="server">
07<title>Hightechnology Repeater Control Example</title>
08</head>
09<body>
10<form id="form1" runat="server">
11<div style="width:800px; margin:0 auto;">
12<asp:Repeater ID="Repeater1" runat="server">
13<HeaderTemplate>
14<table style="border:solid 1px black">
15<tr>
16<td style="width:100px">
17EMP ID
18</td>
19<td style="width:100px">
20Emp Name
21</td>
22<td style="width:100px">
23Salary
24</td>
25<td style="width:100px">
26Designation
27</td>
28</tr>
29</table>
30</HeaderTemplate>
31 
32<ItemTemplate>
33<table style="border:solid 1px black">
34<tr>
35<td style="width:100px">
36<asp:Label ID="empid" Text='<%#Eval("empno") %>' runat="server"></asp:Label>
37</td>
38<td style="width:100px">
39<asp:Label ID="empname" Text='<%#Eval("ename") %>' runat="server"></asp:Label>
40</td>
41<td style="width:100px">
42<asp:Label ID="salary" Text='<%#Eval("basic") %>' runat="server"></asp:Label>
43</td>
44<td style="width:100px">
45<asp:Label ID="designation" Text='<%#Eval("job") %>' runat="server"></asp:Label>
46</td>
47</tr>
48</table>
49</ItemTemplate>
50</asp:Repeater>
51</div>
52</form>
53</body>
54</html>

Code View:

01using System;
02using System.Collections.Generic;
03using System.Linq;
04using System.Web;
05using System.Web.UI;
06using System.Web.UI.WebControls;
07using System.Data;
08using System.Data.SqlClient;
09 
10 
11public partial class _Default : System.Web.UI.Page
12{
13    SqlConnection con = new SqlConnection("Data Source=hightechnology;Initial Catalog=session;Integrated Security=true");
14    protected void Page_Load(object sender, EventArgs e)
15    {
16        Binddata();
17    }
18    public void Binddata()
19    {
20        con.Open();
21        SqlCommand cmd = new SqlCommand("select * from emp", con);
22        DataSet ds = new DataSet();
23        SqlDataAdapter da = new SqlDataAdapter(cmd);
24        da.Fill(ds);
25        Repeater1.DataSource = ds;
26        Repeater1.DataBind();
27        con.Close();
28    }
29}

No comments:

Post a Comment