// fgh.aspx //
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fgh.aspx.cs" Inherits="fgh" %>
<!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">
<asp:Repeater ID="rptPages" Runat="server">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr class="text">
<td><b>Page:</b> </td>
<td>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnPage" CommandName="Page" CommandArgument="<%#Container.DataItem %>" CssClass="text" Runat="server"><%# Container.DataItem %>
</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="rptItems" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><%# Eval("pkItemID") %>: <%# Eval("Description") %></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>
// fgh.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.SqlClient;
using System.Data;
using System.Drawing;
using System.Collections;
public partial class fgh : System.Web.UI.Page
{
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
rptPages.ItemCommand +=
new RepeaterCommandEventHandler(rptPages_ItemCommand);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
LoadData();
}
private void LoadData()
{
SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=rnp;Integrated Security=True;");
cn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from ads", cn);
DataTable dt = new DataTable();
da.Fill(dt);
cn.Close();
PagedDataSource pgitems = new PagedDataSource();
DataView dv = new DataView(dt);
pgitems.DataSource = dv;
pgitems.AllowPaging = true;
pgitems.PageSize = 5;
pgitems.CurrentPageIndex = PageNumber;
if (pgitems.PageCount > 1)
{
rptPages.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1).ToString());
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
rptPages.Visible = false;
rptItems.DataSource = pgitems;
rptItems.DataBind();
}
void rptPages_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
LoadData();
}
}
// SQL TABLE //
No comments:
Post a Comment