ASP.NET提供的Repeater模板并不带有分页功能,如果是少量数据的话利用Repeater模板来实现分页还是不错的,毕竟Repeater模板较为灵活。
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="0">
<tr>
<td><font color="Highlight">编号</font></td>
<td><font color="Highlight">名称</font></td>
<td><font color="Highlight">描述</font></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="LightYellow">
<td>
<%# DataBinder.Eval(Container.DataItem,"CategoryID") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"CategoryName") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"Description") %>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"CategoryID") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"CategoryName") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"Description") %></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
<asp:ImageButton CommandName="previous" ID="previous" ImageUrl=".\images\previous.gif" Runat="server" />
<asp:ImageButton CommandName="next" ID="next" ImageUrl=".\images\next.gif" Runat="server" />
</FooterTemplate>
</asp:Repeater></FONT>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControl