1,首先在web.config设置
<appSettings>
<add key="SocutDataLink" value="server=.;database=MyBookShop;uid=sa;pwd=hxhlxf;"/>
</appSettings>
2,在页面拉入GridView与ASPNetPager控件(通过工具箱引用)
写入代码:
protected void Page_Load(object sender, EventArgs e)
{
AspNetPager1.RecordCount = Convert.ToInt32(Socut.Data.ExecuteScalar("select count(*) from books"));
Bind();
}
public void Bind()
{
DataSet ds = Socut.Data.ExecuteDataSet("select id,title from books",//指定sql语句
AspNetPager1.PageSize*(AspNetPager1.CurrentPageIndex-1),//指定从那条开始查询
AspNetPager1.PageSize);//查询多少条
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
Bind();
}
3、记得把AlwaysShow属性设为true、以为默认清空AspNetPager控件是隐藏的