.aspx
-------------------------------------------------------
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div style="overflow: hidden;">
<div style="float: left; margin: 1px; width: 70px; background: #EAEAFF; text-align:center;">
<%# Eval("ID") %>
</div>
<div style="float: left; margin: 1px; width: 150px; background: #EAEAFF; text-align:center;">
<%# Eval("Items") %>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
<div style="overflow: hidden;">
<asp:Repeater ID="rptPages" runat="server"
onitemcommand="rptPages_ItemCommand1">
<ItemTemplate>
<asp:LinkButton ID="btnPage"
style="padding:1px 3px; margin:1px; background:#ccc; border:solid 1px #666; font:8pt tahoma;"
CommandName="Page" CommandArgument="<%# Container.DataItem %>"
runat="server"><%# Container.DataItem %>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
-------------------------------------------------
.cs
-------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
void LoadData()
{
string constr = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlDataAdapter da = new SqlDataAdapter("select * from rpt_items", constr);
DataTable dt = new DataTable();
da.Fill(dt);
PagedDataSource pgitems = new PagedDataSource();
System.Data.DataView dv = new System.Data.DataView(dt);
pgitems.DataSource = dv;
pgitems.AllowPaging = true;
pgitems.PageSize = 5;
pgitems.CurrentPageIndex = PageNumber;
if (pgitems.PageCount > 1)
{
rptPages.Visible = true;
System.Collections.ArrayList pages = new System.Collections.ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1).ToString());
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
rptPages.Visible = false;
Repeater1.DataSource = pgitems;
Repeater1.DataBind();
}
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}
protected void rptPages_ItemCommand1(object source, RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
LoadData();
}
-------------------------------------------------------
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div style="overflow: hidden;">
<div style="float: left; margin: 1px; width: 70px; background: #EAEAFF; text-align:center;">
<%# Eval("ID") %>
</div>
<div style="float: left; margin: 1px; width: 150px; background: #EAEAFF; text-align:center;">
<%# Eval("Items") %>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
<div style="overflow: hidden;">
<asp:Repeater ID="rptPages" runat="server"
onitemcommand="rptPages_ItemCommand1">
<ItemTemplate>
<asp:LinkButton ID="btnPage"
style="padding:1px 3px; margin:1px; background:#ccc; border:solid 1px #666; font:8pt tahoma;"
CommandName="Page" CommandArgument="<%# Container.DataItem %>"
runat="server"><%# Container.DataItem %>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
-------------------------------------------------
.cs
-------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
void LoadData()
{
string constr = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlDataAdapter da = new SqlDataAdapter("select * from rpt_items", constr);
DataTable dt = new DataTable();
da.Fill(dt);
PagedDataSource pgitems = new PagedDataSource();
System.Data.DataView dv = new System.Data.DataView(dt);
pgitems.DataSource = dv;
pgitems.AllowPaging = true;
pgitems.PageSize = 5;
pgitems.CurrentPageIndex = PageNumber;
if (pgitems.PageCount > 1)
{
rptPages.Visible = true;
System.Collections.ArrayList pages = new System.Collections.ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1).ToString());
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
rptPages.Visible = false;
Repeater1.DataSource = pgitems;
Repeater1.DataBind();
}
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}
protected void rptPages_ItemCommand1(object source, RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
LoadData();
}