日期:2014-05-18 浏览次数:20481 次
<FooterTemplate>
<tr>
<td>
<asp:HyperLink ID="first" runat="server">首页</asp:HyperLink>
<asp:HyperLink ID="next" runat="server">下一页</asp:HyperLink>
<asp:HyperLink ID="up" runat="server">上一页</asp:HyperLink>
<asp:HyperLink ID="last" runat="server">末页</asp:HyperLink>
当前为[<asp:Label ID="lblCurrentPage" runat="server" Text=""></asp:Label>
页] 共[<asp:Label ID="labPage" runat="server" Text=""></asp:Label> 页]
</td></tr>
</table>
</FooterTemplate>
private void BindRepeater()
{
string strSqlConnection = "server=.\\sqlexpress;database=dbArticle;uid=sa;pwd=xiaobai;";
string strSql = "select ID,title,Summary from tnews";
SqlConnection conn=new SqlConnection(strSqlConnection);
conn.Open();
SqlCommand cmd = new SqlCommand(strSql,conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds,"news");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["news"].DefaultView;
//PagedDataSource aa = new PagedDataSource();
pds.AllowPaging = true;//允许分页
pds.PageSize = 8;//单页显示项数
int CurPage;
if (Request.QueryString["Page"] != null)
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage = 1;
pds.CurrentPageIndex = CurPage - 1;
int Count = pds.PageCount;
((Label)this.RepterArticle.FindControl("lblCurrentPage")).Text = "当前页:" + CurPage.ToString();//提示错误在这一行,未将对象引用设置到对象的实例。
((Label)this.RepterArticle.FindControl("labPage")).Text = Count.ToString();
}