<P><WEBDIYER:ASPNETPAGER id="pager" runat="server" SubmitButtonText="转到" ShowPageIndex="False" PageSize=2
ShowInputBox="Always" LastPageText="<font style='FONT-SIZE: x-small'>最后页</fornt>" NextPageText="<font style='FONT-SIZE: x-small'>下一页</fornt>"
PrevPageText="<font style='FONT-SIZE: x-small'>前一页</fornt>" FirstPageText="<font style='FONT-SIZE: x-small'>最前页</fornt>"
InputBoxStyle="border:1px #0000FF solid;text-align:center;FONT-SIZE: x-small" TextBeforeInputBox="第"
TextAfterInputBox="页" ShowCustomInfoSection="left" AlwaysShow="True" CustomInfoTextAlign="Center"
SubmitButtonStyle="width:40px;height:21px;"></webdiyer:AspNetPager></P>
<P><asp:datagrid id="dgrid1" runat="server"></asp:datagrid></P>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace InfoId.cc
{
/// <summary>
/// test 的摘要说明。
/// </summary>
public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgrid1;
protected Wuqi.Webdiyer.AspNetPager pager;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
BindData();
}

}
private void BindData()
{
SqlConnection conn =new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["SqlConnectionString"].ToString());
SqlCommand cmd=new SqlCommand("select * from test",conn);
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
//注意下面这句,只填充当前页要显示的数据,不能把所有数据全填充到DataSet中,否则无法实现分页
da.Fill(ds,pager.PageSize*(pager.CurrentPageIndex-1),pager.PageSize,"newtable");
dgrid1.DataSource=ds.Tables["newtable"];
dgrid1.DataBind();
DataSet ds1=new DataSet();
da.Fill(ds1);
pager.RecordCount=ds1.Tables[0].Rows.Count;
// 动态设置用户自定义文本内容
pager.CustomInfoText = "记录总数:<font color='blue'><b>" + pager.RecordCount.ToString() + "</b></font>";
pager.CustomInfoText += " 总页数:<font color='blue'><b>" + pager.PageCount.ToString() + "</b></font>";
pager.CustomInfoText += " 当前页:<font color='red'><b>" + pager.CurrentPageIndex.ToString() + "</b></font>";

}


Web 窗体设计器生成的代码
private void pager_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
pager.CurrentPageIndex = e.NewPageIndex;
BindData();
System.Text.StringBuilder sb=new System.Text.StringBuilder("<script Language=\"Javascript\"><!--\n");
sb.Append("var el=document.all;");
sb.Append(dgrid1.ClientID);
sb.Append(".scrollIntoView(true);");
sb.Append("<");
sb.Append("/");
sb.Append("script>");
if(!Page.IsStartupScriptRegistered("scrollScript"))
Page.RegisterStartupScript("scrollScript",sb.ToString());

}
}
}



浙公网安备 33010602011771号