<!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与Socut.Data使用</title>
<style type="text/css">
body{font:12px tahoma;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvwTest" runat="server" AutoGenerateColumns="false">
<columns>
<asp:BoundField DataField="Id" HeaderText="ID" HeaderStyle-Width="50" />
<asp:BoundField DataField="username" HeaderText="姓名" HeaderStyle-Width="200" />
</columns>
</asp:GridView>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged" PageSize="10" UrlPaging="True">
</webdiyer:AspNetPager>
</div>
</form>
</body>
</html>
cs文件:
protected void Page_Load(object sender, EventArgs e)
{
AspNetPager1.RecordCount = (int)Socut.Data.ExecuteScalar("select count(*) from admin");
if (!Page.IsPostBack)
{
datainit();
}
}
private void datainit()
{
DataSet ds = Socut.Data.ExecuteDataSet("select * from admin", AspNetPager1.PageSize*(AspNetPager1.CurrentPageIndex - 1),AspNetPager1.PageSize);
gvwTest.DataSource = ds;
gvwTest.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
datainit();
}
先引入控件,然后写小部分代码就能实现简单分页效果,方便快效,是我决定在以后项目中采用它的原因。而它的分页样式可以十分灵活的控制,比如我改成如下:
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com