首先下载:AspNetPager.dll AspNetPager.xml Aspose.Words.dll 放到bin目录下
后台绑定事件
页面添加<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center" onpagechanged="AspNetPager1_PageChanged"
showcustominfosection="Left" width="100%" meta:resourcekey="AspNetPager1" style="font-size: 14px"
inputboxstyle="width:19px" custominfohtml="一共有<b><font color='red'>%RecordCount%</font></b>条记录 当前页<font color='red'><b>%CurrentPageIndex%/%PageCount%</b></font> 次序 %StartRecordIndex%-%EndRecordIndex%"
alwaysshow="True" firstpagetext="首页" lastpagetext="尾页" nextpagetext="下一页" prevpagetext="上一页"
custominfostyle="FONT-SIZE: 12px" pagesize="5">
</webdiyer:aspnetpager>
后台绑定事件
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
Databind();
}
gridview绑定事件
public void Databind()
{
DataTable dt = 。。。;
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;//索引同步
pds.DataSource = dt.DefaultView;
GridView1.DataSource = pds;//数据绑定
GridView1.DataBind();
AspNetPager1.RecordCount = dt.Rows.Count;
}
gridview搜索时要注意联动,不然webdiyer控件会保存上一次的数据
protected void btsearch_Click1(object sender, EventArgs e)
{
//搜索条件
DataTable dt = 搜索结果datatable;
if (dt.Rows.Count == 0)
{
ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('没有查到符合条件的数据');", true);
Databind();
return;
}
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = dt.DefaultView;
GridView1.DataSource = pds;
GridView1.DataBind();
AspNetPager1.RecordCount = dt.Rows.Count;
}
gridview有删除或者编辑更新功能时,要注意最后将GridView1.SelectedIndex = -1;