如题,请各位介绍下 aspnetpager控件的 常用 属性 以及 事件结合Repeater使用...欢迎讨论
解决方案 »
- 100分如何用asp.net获得自动提交后的网页源代码
- 请教 <%# DataBinder.Eval(Container.DataItem, "title") %> 如何和 IF 连接起来
- 急!在 session 中 存放 ArrayList 碰到一个很奇怪的问题?
- 动态服务器控件如何传值
- 每个用户每天只能发一条信息怎样实现?
- VS 2005开始的时候有个习惯设置??就是C#,VB.NET还是网站...我选错了,想修改,怎么办?
- 想关闭页面,为什么点两下才关?
- 请教下,我开多少工资?顺便问下大家的工资水平
- 关于cookie 的问题。。
- 实现两台机器的目录文件同步???(吐血分,分不够可以加)
- SiteMap能否可以存在多个相同节点?
- 谈谈大家对jquery的心得吧
事件一般就是AspNetPager1_PageChanged,基本上就是下面这些了/* 分页控件的样式*/
.anpager .cpb {background:#1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px 0 0;padding:4px 5px 0;}
.anpager a {background:#FFFFFF none repeat scroll 0 0;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px 0 0;padding:4px 5px 0;text-decoration:none}
.anpager a:hover{background:#1F3A87 none repeat scroll 0 0;border:1px solid #1F3A87;color:#FFFFFF;}
-------------------------------------------------------------------------------
当前页/总页数:<%=AspNetPager1.CurrentPageIndex %>/<%=AspNetPager1.PageCount %>总共:<%=AspNetPager1.RecordCount %>条
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged"
PageSize="10" AlwaysShow="true" CssClass="anpager" CurrentPageButtonClass="cpb"
FirstPageText="首页" LastPageText="尾页" NextPageText="后页" PrevPageText="前页">
</webdiyer:AspNetPager>
<webdiyer:AspNetPager ID="Pager"
runat="server"
AlwaysShow="true"
CustomInfoHTML=""
CustomInfoSectionWidth="40%"
FirstPageText="首页"
LastPageText="尾页"
NextPageText="下一页"
OnPageChanged="Pager_PageChanged"
PageIndexBoxType="DropDownList"
PageSize="10"
PrevPageText="上一页"
ShowCustomInfoSection="Left"
ShowPageIndexBox="Always"
SubmitButtonText="Go"
TextAfterPageIndexBox=""
TextBeforePageIndexBox=""
UrlPaging="true">
</webdiyer:AspNetPager>使用很简单
private void BindInfo()
{
Pager.CurrentPageIndex = (Int32)Request.QueryString("page");
DataSet ds=....//获取数据
if (ds!=null && ds.Tables[0]!=null && ds.Tables[0].Rows.Count > 0)
{
Pager.RecordCount = ds.Tables[0].Rows.Count ;
rpt.DataSource = ds.Tables[0].DefaultView; }
else
{
Pager.RecordCount = 0;
rpt.DataSource = null;
} rpt.DataBind();
} pager的PageChanged事件中执行 BindInfo方法就行
PageChanged 事件中要添加绑定repeater的代码 留个邮箱我发你个例子吧
public int Fill(
DataSet dataSet,
int startRecord,
int maxRecords,
string srcTable
);就可以了
然后再绑定每页的数据,如定义了BindRpt()
private void BindRpt()
{
DBConn db=new DBConn();
string sql = "select * from (select a.*, rownum r from (select * from articlecomment order by commentDate desc) a where rownum <= " + AspNetPager2.EndRecordIndex + ") b where r >= " + AspNetPager2.StartRecordIndex;
Datatable dt = db.ExecuteDatatable(sql);
Repeater1.DataSource=dt;
Repeater1.DataBind();
}protected void AspNetPager2_PageChanged(object sender, EventArgs e)
{
BindRpt();
}注意sql语句(oracle的),如你设置了分页数15,那么每次取出的记录就是15条。
sqlserver中好像是用top 15这样来分的。。就这么简单
那你把这个方法拿出来看看呗 我写的是用datareader存数据,做数据源给Repeater
public IList<NewsInfo> BindData()
{
int CurrentPage = this.AspNetPager1.CurrentPageIndex;
int PageSize = this.AspNetPager1.PageSize;
int startIndex = (CurrentPage - 1) * PageSize + 1;
int endIndex = startIndex + PageSize - 1;
string sql = string.Format("select * from (select *,row_number() over(order by NewsID desc) as rowNum from News ) as myTable where rowNum between {0} and {1}", startIndex, endIndex);
SqlConnection connStr = new SqlConnection("Data Source = wq-wq;Initial Catalog = NewsPublish;uid = sa;pwd = 123");
SqlCommand cmd = new SqlCommand(sql, connStr);
connStr.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
NewsInfo newsInfo = new NewsInfo();
newsInfo.NewsID = Convert.ToInt32(sdr["NewsID"].ToString());
newsInfo.TitleName = sdr["TitleName"].ToString();
newsInfo.NewsContent = sdr["NewsContent"].ToString();
newsList.Add(newsInfo);
}
return newsList;
}