时间:2021-05-28
实现代码如下:
复制代码 代码如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
namespace ShowData4
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.PageSize = 5;
if (GridView1.Rows.Count != 0)
{
Control table = GridView1.Controls[0];
int count = table.Controls.Count;
table.Controls[count - 1].Visible = true;
}
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
LinkButton Button_IndexFirst = new LinkButton();
LinkButton Button_IndexLast = new LinkButton();
LinkButton Button_IndexNext = new LinkButton();
LinkButton Button_IndexPrevious = new LinkButton();
e.Row.Controls[0].Controls.Add(Button_IndexFirst);
e.Row.Controls[0].Controls.Add(new LiteralControl((" ")));
e.Row.Controls[0].Controls.Add(Button_IndexPrevious);
e.Row.Controls[0].Controls.Add(new LiteralControl((" ")));
e.Row.Controls[0].Controls.Add(Button_IndexNext);
e.Row.Controls[0].Controls.Add(new LiteralControl((" ")));
e.Row.Controls[0].Controls.Add(Button_IndexLast);
Button_IndexFirst.Text = "第一页";
Button_IndexFirst.CommandName = "first";
Button_IndexFirst.Click += new EventHandler(PageButtonClick);
Button_IndexPrevious.Text = "上一页";
Button_IndexPrevious.CommandName = "previous";
Button_IndexPrevious.Click += new EventHandler(PageButtonClick);
Button_IndexNext.Text = "下一页";
Button_IndexNext.CommandName = "next";
Button_IndexNext.Click += new EventHandler(PageButtonClick);
Button_IndexLast.Text = "最后一页";
Button_IndexLast.CommandName = "last";
Button_IndexLast.Click += new EventHandler(PageButtonClick);
if (GridView1.PageIndex == 0)
{
if (GridView1.PageCount > 1)
{
Button_IndexFirst.Enabled = false;
Button_IndexPrevious.Enabled = false;
}
else
{
Button_IndexFirst.Enabled = false;
Button_IndexPrevious.Enabled = false;
Button_IndexNext.Enabled = false;
Button_IndexLast.Enabled = false;
}
}
else if (GridView1.PageIndex == GridView1.PageCount - 1)
{
Button_IndexNext.Enabled = false;
Button_IndexLast.Enabled = false;
}
else if (GridView1.PageCount <= 0)
{
Response.Write("数据表中没有数据!");
Button_IndexFirst.Enabled = false;
Button_IndexPrevious.Enabled = false;
Button_IndexNext.Enabled = false;
Button_IndexLast.Enabled = false;
}
}
}
protected void PageButtonClick(object sender, EventArgs e)
{
LinkButton clickedButton = ((LinkButton)sender);
if (clickedButton.CommandName == "first")
{
GridView1.PageIndex = 0;
}
else if (clickedButton.CommandName == "next")
{
if (GridView1.PageIndex < GridView1.PageCount - 1)
{
GridView1.PageIndex += 1;
}
}
else if (clickedButton.CommandName == "previous")
{
if (GridView1.PageIndex >= 1)
{
GridView1.PageIndex -= 1;
}
}
else if (clickedButton.CommandName == "last")
{
GridView1.PageIndex = GridView1.PageCount - 1;
}
}
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
asp.net操作access数据库是常见的数据库操作应用,本文就来实例讲解一下asp.net实现access数据库分页的方法。希望对大家的asp.net程序设
从SQLServer2005开始提供了一种新的数据类型XMLtype,它允许用户将数据以XML文件的格式直接存储到数据表中。结合在ASP.NET中使用Linqt
通常分页有3种方法,分别是asp.net自带的数据显示空间如GridView等自带的分页,第三方分页控件如aspnetpager,存储过程分页等。这里分别做总结
在ASP.NET中有很多数据展现的控件,比如用的最多的GridView,它同时也自带了分页的功能。但是我们知道用GridView来显示数据,如果没有禁用View
查询功能是开发中最重要的一个功能,大量数据的显示,我们用的最多的就是分页。在ASP.NET中有很多数据展现的控件,比如Repeater、GridView,用的最