Screenshot
Sekil 1
Sekil 2
Sekil 3
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;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Repeater1.Page.Visible= true;
if (!IsPostBack)
{
bindData();
}
}
protected void bindData()
{
SqlConnection baglan = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\kategori.mdf;Integrated Security=True");
{
baglan.Open();
SqlCommand cmd = new SqlCommand("select * from [dbo].[Table]", baglan);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
PagedDataSource sayfads = new PagedDataSource();
DataView dv = new DataView(ds.Tables[0]);
sayfads.DataSource = dv;
sayfads.AllowPaging = true;
sayfads.PageSize = 5;
if (ViewState["SayfaNo"] != null)
sayfads.CurrentPageIndex = Convert.ToInt32(ViewState["SayfaNo"]);
else
sayfads.CurrentPageIndex = 0;
if (sayfads.PageCount > 1)
{
rptSayfalama.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < sayfads.PageCount; i++)
pages.Add((i + 1).ToString());
rptSayfalama.DataSource = pages;
rptSayfalama.DataBind();
}
else
{
rptSayfalama.Visible = false;
}
Repeater1.DataSource = sayfads;
Repeater1.DataBind();
baglan.Close();
}
}
protected void rptSayfalama_ItemCommand(object source, RepeaterCommandEventArgs e)
{
ViewState["SayfaNo"] = Convert.ToInt32(e.CommandArgument) - 1;
bindData();
}
}
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 id="tblDetay" style="width:500px; border-collapse: collapse;" border="1" cellpadding="5" cellspacing="0" >
<tr style="background-color: #ff0000; height: 30px; color:#fff" align="center">
<th>Id</th>
<th>Yazar</th>
<th>Kitap</th>
<th>Fiyat</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="height: 25px;">
<td >
<%#Eval("id").ToString()%>
</td>
<td >
<%#Eval("yazar").ToString()%>
</td>
<td>
<%#Eval("kitap").ToString()%>
</td>
<td >
<%#Eval("fiyat").ToString()%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div><br />
<asp:Repeater ID="rptSayfalama" runat="server" onitemcommand="rptSayfalama_ItemCommand">
<ItemTemplate>
<asp:LinkButton ID="lnkPage"
style="padding:10px; margin:2px; background:#000000; border:solid 1px #666; color:#fff; font-weight:bold"
CommandName="Page" CommandArgument="<%# Container.DataItem %>"
runat="server" Font-Bold="True"><%# Container.DataItem %>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
<br />
</form>
</body>
</html>
Bir makalenin daha sonuna geldik. Bir sonraki makalede görüsmek üzere. Bahadir SAHIN
0 comments:
Yorum Gönder