GridView 如何实现 AspNetPager 分页??

cbting 2010-04-24 05:38:34
GridView 如何实现 AspNetPager 分页?? 用数据库取到的数据是DataTable 如何在 GridView 与 AspNetPager 绑定分页??
...全文
195 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunzhong2003 2010-04-25
  • 打赏
  • 举报
回复
找分页空间的管网,下个DEMO,大侠一句做了不少了,可以很好的参考
zhouwei7682719 2010-04-25
  • 打赏
  • 举报
回复
随便搜一下 一大片
kk297173176 2010-04-25
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
int curpage = 1;
private void bind()
{
string sqlconn = System.Configuration.ConfigurationManager.ConnectionStrings["sql"].ToString();
SqlConnection conn = new SqlConnection(sqlconn);
SqlDataAdapter sda = new SqlDataAdapter("select * from tb_user", conn);
DataSet ds = new DataSet();

conn.Open();
sda.Fill(ds);
conn.Close();

this.AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
this.GridView1.AllowPaging = true;
this.GridView1.PageIndex = curpage;
this.GridView1.PageSize = 15;
this.AspNetPager1.PageSize = 15;

this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
curpage = e.NewPageIndex-1;
bind();
}
oyjd614 2010-04-25
  • 打赏
  • 举报
回复
代码如下,希望对你有所帮助

private void BindData(int pageIndex)
{
// Get datasource
// To do
// Settding aspnetpager record count
anpNews.RecordCount = currentPage.TotalCount;
// Bind datasource
}
protected void anpNews_PageChanged(object sender, EventArgs e)
{
BindNewsList(anpNews.CurrentPageIndex - 1);
}


<ccl:AspNetPager ID="anpNews" runat="server" HorizontalAlign="Center" PageSize="13"
CurrentPageButtonClass="cpb" CssClass="anpager" AlwaysShow="True" OnPageChanged="anpNews_PageChanged"
ShowFirstLast="true" ShowPrevNext="true" NextPageText="下一页" PrevPageText="上一页"
FirstPageText="首页" LastPageText="尾页">
</ccl:AspNetPager>
vip__888 2010-04-25
  • 打赏
  • 举报
回复
google grv72变
gdlpc 2010-04-25
  • 打赏
  • 举报
回复
测试通过的
//aspx页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AspNetPager.aspx.cs" Inherits="AspNetPager" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

<!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>AspNetPager分页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="首页" LastPageText="末页" NextPageText="下一页" PrevPageText="上一页" ShowCustomInfoSection="Left" ShowNavigationToolTip="True" SubmitButtonText="go转到" OnPageChanged="AspNetPager1_PageChanged" Font-Size="10pt" Width="457px">
</webdiyer:AspNetPager>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>

</div>
</form>
</body>
</html>

//.cs页面:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.SqlClient;

public partial class AspNetPager : System.Web.UI.Page
{
DataSet ds;
SqlDataAdapter dr;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["SperConnectionString1"].ToString();
string strconn = "Data Source=(local);Database=INFO;Uid=sa;Pwd=5354";
SqlConnection con = new SqlConnection(strconn);
con.Open();
com = new SqlCommand();
com.Connection = con;
com.CommandText = "select count(*) from zhong";
AspNetPager1.AlwaysShow = true;
//AspNetPager1.PageSize = 5;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
RepeaterDataBind();
}
}

private void RepeaterDataBind()
{
//string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["SperConnectionString1"].ToString();
string strconn = "Data Source=(local);Database=INFO;Uid=sa;Pwd=5354";
dr = new SqlDataAdapter("select * from zhong", strconn);
ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "zhong");
this.GridView1.DataSource = ds.Tables["zhong"];
this.GridView1.DataBind();

AspNetPager1.CustomInfoHTML = " 总页数:<b>" + AspNetPager1.PageCount.ToString() + "</b>";
AspNetPager1.CustomInfoHTML += " 当前页:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
}

protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
RepeaterDataBind();
}
//protected string FormatString_Size_13(string str)
//{//这里的代码可以不使用
// if (str.Length > 33)
// {
// str = str.Substring(0, 32) + "";
// }
// return str;
//}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
RepeaterDataBind();
}
}

woanon 2010-04-25
  • 打赏
  • 举报
回复
好多方法,最简单的就是套个分页控件
  • 打赏
  • 举报
回复
~~~~~~~~~~~~~~
andyxl 2010-04-24
  • 打赏
  • 举报
回复
网上看下嘛。
threenewbee 2010-04-24
  • 打赏
  • 举报
回复

62,052

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧