Repeater, Database deki verilerin gösteriminde kullanılan en yaygın nesnelerden biridir. Bu nesnede uygulamamızda da görebileceğiniz gibi;
< HeaderTemplate > < / HeaderTemplate > kısmına Repeater in sütun başlıklarını oluştururuz.
< ItemTemplate >< / ItemTemplate > ve < AlternatingItemTemplate > < / AlternatingItemTemplate > kısmına veriyi çekeceğimiz nesneler ve veritabanı bağlantısı yapılır.
< FooterTemplate > < / FooterTemplate > > kısmında da alt başlıklar ekleyebilirsiniz.
Default.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;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected int count;
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data//Northwind.mdb"));
OleDbCommand cmd=new OleDbCommand ("Select CustomerID, ContactName, Country From Customers Where CustomerID LIKE 'A%'", baglan);
baglan.Open();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
baglan.Close();
Repeater1.DataSource = dt;
Repeater1.DataBind();
count = dt.Rows.Count;
}
Default.aspx
< %@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" % >
< !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 ID="Repeater1" runat="server" >
< HeaderTemplate >
< table border="1" bordercolor="#cccccc" cellpadding="0" cellspacing="0" >
< tr >
< td bgcolor="#ff8040" >
< font color="White" >< center >< b >Customer ID< / b >< / center >< / font >
< / td >
< td bgcolor="#ff8040" >
< font color="White" >< center >< b >Contact Name< / b >< / center >< / font >
< / td >
< td bgcolor="#ff8040" >
< font color="White" >< center >< b >Country< / b >< / center >< / font >
< / td >
< / tr >
< / HeaderTemplate >
< ItemTemplate >
< tr bgcolor="#0099ff" >
< td >
< font color="White" >< b >< %#Eval("CustomerID")% >< / b >< / font >
< / td >
< td >
< font color="White" >< b >< %#Eval("ContactName")% >< / b >< / font >
< / td >
< td >
< font color="White" >< b >< %#Eval("Country")% >< / b >< / font >
< / td >
< / tr >
< / ItemTemplate >
< AlternatingItemTemplate >
< tr bgcolor="#FFFFFF" >
< td >
< %#Eval("CustomerID")% >
< / td >
< td >
< %#Eval("ContactName")% >
< / td >
< td >
< %#Eval("Country")% >
< / td >
< / tr >
< / AlternatingItemTemplate >
< FooterTemplate >
< tr >
< td >
< b >Kayıt Sayısı : < / b >
< / td >
< td >
< b >< %=count% >< / b >
< / td >
< / tr >
< / table >
< / FooterTemplate >
< / asp:Repeater >
< / div >
< / form >
< / body >
< / html >
0 comments:
Yorum Gönder