1.use repeater
Code
<asp:Repeater ID="Repeater_list" runat="server">
<ItemTemplate>
<div id="wrap" onmouseover="this.style.backgroundColor='#ddfffc'" onmouseout="this.style.backgroundColor='#fff'">
<div id="title">
标题:<a href='n_showNews.aspx?id=<%#DataBinder.Eval(Container.DataItem, "n_id") %> ' target="_blank">
<strong> <%#DataBinder.Eval(Container.DataItem, "n_title")%></strong> </a>
<div id="linkPart">
<a href='n_showNews.aspx?id=<%#DataBinder.Eval(Container.DataItem, "n_id") %> ' target="_blank">详细信息</a>
</div>
</div>
<div class="text"> <%--属性--%>
<div class="table">
新闻类别 <%#DataBinder.Eval(Container.DataItem, "n_classname")%>
</div>
<div class="table">
阅读次数: <%#DataBinder.Eval(Container.DataItem, "n_readNum")%>
</div>
<div class="table">
新闻来源: <%#DataBinder.Eval(Container.DataItem, "n_from")%>
</div>
<div class="table">
发布单位: <a href='E_showEnterprise.aspx?id=<%#DataBinder.Eval(Container.DataItem, "e_id") %> ' target="_blank"> <%#DataBinder.Eval(Container.DataItem, "e_name")%> </a>
</div>
<div id="enterprise">
发布时间: <%#DataBinder.Eval(Container.DataItem, "n_pubdate", "{0:yyyy年MM月dd日HH时mm分}")%>
</div>
</div>
<div class="text"> <%--简要信息--%>
<a href='n_showNews.aspx?id=<%#DataBinder.Eval(Container.DataItem, "n_id") %> ' target="_blank">
<%#SubStr(Convert.ToString(DataBinder.Eval(Container.DataItem, "n_content")), 50)%></a>
<a href='n_showNews.aspx?id=<%#DataBinder.Eval(Container.DataItem, "n_id") %> ' target="_blank">[详细]</a>
</div>
</div>
</ItemTemplate>
</asp:Repeater> 2.use asppager
Code
3.write the code.
Code
1 this.AspNetPager1.RecordCount = news.GetRecordCount(queryItems);
2 BindData();
3
Code
1
2 /// <summary>
3 /// 绑定全部分页数据
4 /// </summary>
5 protected void BindData()
6 {
7
8 int startIndex = AspNetPager1.StartRecordIndex;
9 int pageSize = AspNetPager1.PageSize;
10
11 DataSet ds = new DataSet();
12 ds = news.QueryNews(startIndex, pageSize);
13
14
15
16 Repeater_list.DataSource = ds;
17 Repeater_list.DataBind();
18 }
19
<div id="page" style="text-align:center; 499px;">
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="首页"
LastPageText="尾页" NextPageText="后页" PrevPageText="前页" Width="500px"
CenterCurrentPageButton="True" PageIndexBoxType="DropDownList"
ShowPageIndexBox="Always" SubmitButtonText="Go" TextAfterPageIndexBox="页"
TextBeforePageIndexBox="转到" NumericButtonCount="5"
CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条"
ShowCustomInfoSection="Right"
onpagechanging="AspNetPager1_PageChanging" PageSize="2">
</webdiyer:AspNetPager>
</div> 4.
summarize one's work
To sum up,the repeater call for the aspager 's pagination
methods.But we have to make sure the
front desk's code is correct.Make sure your databinder.
You should get the total RecordCount from your database at first.then, get startIndex from AspNetPager1.StartRecordIndex and pageSize from AspNetPager1.PageSize;
next,use a procedure or select Command SQL to get whole data.
at last,set up to your data view control such as gridview,repeater and so on.
Repeater_list.DataSource = ds;
Repeater_list.DataBind();
Above all,you must pay attention to your a procedure or select Command SQL.
Enjoy it.thanks.
作者:johnny
出处:http://www.cnblogs.com/sunjunlin
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。