Repeater Nesnesinde AlternatingItemTemplate Kullanımı
Merhaba arkadaşlar bu makalemizde Repeater nesnesinde AlternatingItemTemplate kullanarak, Repeater nesnesinin satır renklerini değiştireceğiz.
Screenshoot
Şekil 1
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Repeater();
}
}
private void Repeater()
{
SqlConnection baglan = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\kategori.mdf;Integrated Security=True;Connect Timeout=30");
SqlCommand komut = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter(komut);
DataSet ds = new DataSet();
komut.CommandText = "Select * From [Table]";
komut.Connection = baglan;
baglan.Open();
komut.ExecuteNonQuery();
da.Fill(ds);
baglan.Close();
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
}
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<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="0" width="50%">
<tr>
<th align="left">Id</th>
<th align="left">Author</th>
<th align="left">Book Name</th>
<th align="left">Price</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="#c4c4c4">
<td><%#Eval("Id") %> </td>
<td><%#Eval("Yazar") %> </td>
<td><%#Eval("Kitap") %> </td>
<td><%#Eval("Fiyat") %> </td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="#e4e4e4">
<td><%#Eval("Id") %> </td>
<td><%#Eval("Yazar") %> </td>
<td><%#Eval("Kitap") %> </td>
<td><%#Eval("Fiyat") %> </td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN