日期:2014-05-18 浏览次数:20516 次
<div style="width:87%">
<asp:DataList ID="dlNewsList" runat="server" Width="642px">
<ItemTemplate>
<table border="0" cellspacing="0" cellpadding="0" style="line-height:14px; width: 90%;">
<tr>
<td align="left" style="padding-left:20px; height: 22px;text-decoration:none">·
<a href='NewDetail_ce.aspx?id=<%# Eval("id") %>' style="color:#686865">
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("title") %>'></asp:Label></a></td>
<td style="height: 13px; width: 70px;">
[<asp:Label ID="lblPubDate" runat="server" Text='<%# GetDate(Eval("RELEASE_TIME").ToString()) %>'></asp:Label>]</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
<div style="text-align: center">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td >
<webdiyer:AspNetPager ID="anpNews" runat="server" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" ShowPageIndex="false" OnPageChanged="anpNews_PageChanged" PageSize="10"> </webdiyer:AspNetPager></td>
<td >
<asp:Label ID="lblCurrentPage" runat="server"></asp:Label></td>
</tr>
</table>
</div>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindNews();
}
}
//<summary>
//截取时间字符串,获取年月日
//</summary>
//<param name="date"></param>
protected string GetDate(string date)
{
return date;
}
/// <summary>
/// 获取新闻列表
/// </summary>
public void BindNews()
{
DataTable ds = DBHelper.GetDataSet("select * from News where type='xw' order by id desc");
PagedDataSource pds = new PagedDataSource();
anpNews.RecordCount = ds.DefaultView.Count;
pds.DataSource = ds.DefaultView;
pds.AllowPaging = true;
pds.CurrentPageIndex = anpNews.CurrentPageIndex - 1;
pds.PageSize = anpNews.PageSize;
lblCurrentPage.Text = " 共" + pds.PageCount.ToString() + "页";
this.dlNewsList.DataSource = pds;
this.dlNewsList.DataBind();
ds.Dispose();
}
/// <summary>
/// 实现分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void anpNews_PageChanged(object sender, EventArgs e)
{
BindNews();
}