GRIDVIEW两种分页代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第一种分页
A.aspx文件
<%@ Page Language="C#" CodeFile="真分页.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="/1999/xhtml" >
<head runat="server">
<title>自定义代码实现真分页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<br />
共有记录<asp:Label ID="lblrecordamount" runat="server" BackColor="White" ForeColor="Red"></asp:Label>条 每页显示<asp:Label
ID="lblpagesize" runat="server" BackColor="White" ForeColor="Red"></asp:Label>条<br />
共有<asp:Label ID="lblpagecount" runat="server" BackColor="White"
ForeColor="Red"></asp:Label>页 当前是第<asp:Label
ID="lblcurpageindex" runat="server" BackColor="White" ForeColor="Red"></asp:Label>页<br />
<br />
<asp:LinkButton ID="lbFirst" runat="server" CommandName="first" OnCommand="lbLast_Command">首页</asp:LinkButton>
<asp:LinkButton ID="lbPrev" runat="server" CommandName="prev" OnCommand="lbLast_Command">上一页</asp:LinkButton>
<asp:LinkButton ID="lbNext" runat="server" CommandName="next" OnCommand="lbLast_Command">下一页</asp:LinkButton>
<asp:LinkButton ID="lbLast" runat="server" CommandName="last" OnCommand="lbLast_Command">尾页</asp:LinkButton> 直接跳转到<asp:DropDownList
ID="ddl" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged">
</asp:DropDownList>页</div>
</form>
</body>
</html>
A.aspx.cs文件
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
private int recordamount = 0; //表中的记录总数
private int pagesieze = 5; //每页显示多少条记录
private int pagecount = 0; //共需要分多少页
private int curpageindex = 0; //当前是第几页
protected void Page_Load(object sender, EventArgs e)
{
//第一次请求该页时初始化recordamount、pagesieze、pagecount这3个值,这3个值在以后的显示中都不会改变
if (!this.IsPostBack)
{
SqlDataSource ds = new SqlDataSource();