您的位置:首页 > 编程语言 > ASP

AspNetPager.dll 分页控件使用

2014-02-27 09:28 537 查看
今天在用.net 做网站的时候,用到了DATALIST,但是datalist 没有自带的分页控件,后来在网上找了好长时间,看了aspnetpager.dll这个控件,这个控件挺好用的.我把使用方法写出来,大家可以参考一下。

先网上下载一个分页的控件。AspNetPager.dll 这个文件。

先引用进来,添加引用那里添加进来。你也可以到工具箱那里,添加引用一下,工具箱上会多一个分页的控件的,到时候只要拖进到页面上就行了。

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

这个放到页面头部

<webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" NumericButtonCount="6" UrlPaging="true" NumericButtonTextFormatString="[{0}]" CustomInfoHTML="第 <font color='red'><b>%CurrentPageIndex%</b></font> 页 共 %PageCount% 页 显示 %StartRecordIndex%-%EndRecordIndex% 条" ShowCustomInfoSection="left"
FirstPageText="首页" LastPageText="末页" NextPageText="下页" PrevPageText="上页" Font-Names="Arial" BackColor="#EDEDED" AlwaysShow="true" SubmitButtonText="跳转" SubmitButtonStyle="botton" OnPageChanging="AspNetPager1_PageChanging1" HorizontalAlign="Right" >
</webdiyer:AspNetPager>

这个是一个写好的分页控件。样式都写好了~!

bind() 这个 方法可以写到页面加载的地方load里面

if(!ispostback)

{

bind();

}

-------------------------------------------------------------------------

private void bind()
{

DataSet ds = new DataSet();
string sql = "select b.* from users";
ds = conn.GetReader(sql);///用来统计总数用。。。。。conn.GetReader()是自己写的一个方法返回dataset
this.AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;/////需要把记录的总数统计出来赋值给控件
int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;//定义要显示的页面
int pageSize = this.AspNetPager1.PageSize = 6;///定义每页显示6条信息

DataSet dd = new DataSet();
dd = GVBind(sql, pageIndex, pageSize);

this.dlp.DataSource = dd;
dlp.DataBind();

}

protected void AspNetPager1_PageChanging1(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
bind();
}

public static DataSet GVBind(string strCom, int i1, int i2)
{
int firstPage = i1 * i2;

SetConnection();/////调用数据链接的,我就不写出来
DataSet ds = new DataSet();
OleDbDataAdapter myDbAdp = new OleDbDataAdapter(strCom, myDbCon);

myDbAdp.Fill(ds, firstPage, i2, "article");
return ds;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: