<!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();
}
先引入控件,然后寫小部分代碼就能實(shí)現(xiàn)簡(jiǎn)單分頁效果,方便快效,是我決定在以后項(xiàng)目中采用它的原因。而它的分頁樣式可以十分靈活的控制,比如我改成如下:
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com