Front-end code:
Code
Copy codeThe Code is as follows:
<Div id = "newslistdiv">
<Asp: DataList ID = "NewsList" runat = "server" Width = "820px">
<HeaderTemplate>
<Div>
</div>
</HeaderTemplate>
<ItemTemplate>
<Dl>
<Dd>
· <A href = "#" class = "rlk" onclick = 'window. location. href = "DetailNews. aspx? ID = <% # Eval ("NewsID") %> "'> <% # Eval (" NewsTitle ") %> </a>
<% # Eval ("NewsTime", "{0: yyyy-MM-dd}") %> <br/>
</Dd>
</Dl>
</ItemTemplate>
</Asp: DataList>
</Div>
<Div style = "margin-bottom: 2px;" align = "center">
<Webdiyer: AspNetPager ID = "AspNetPager1" runat = "server" PageSize = "15" FirstPageText = "Homepage"
LastPageText = "last page" NextPageText = "next page" OnPageChanged = "AspNetPager1_PageChanged"
PrevPageText = "Previous Page" Width = "100%" AlwaysShow = "true" CssClass = "anpager">
</Webdiyer: AspNetPager>
</Div>
Background code:
Code
Copy codeThe Code is as follows:
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
BindNewsDatalist ();
}
}
// Data source bound to DataList
Private void BindNewsDatalist ()
{
FJDWS. BusinessLogic. LNewsManager lnewsmanager = new FJDWS. BusinessLogic. LNewsManager ();
This. AspNetPager1.RecordCount = lnewsmanager. FindAll (). Count;
PagedDataSource PPS = new PagedDataSource (); // defines a PagedDataSource class to perform the paging function.
PPS. DataSource = lnewsmanager. FindAll ();
PPS. AllowPaging = true;
PPS. CurrentPageIndex = AspNetPager1.CurrentPageIndex-1;
PPS. PageSize = AspNetPager1.PageSize;
This. NewsList. DataSource = pds;
NewsList. DataBind ();
}
Protected void AspNetPager1_PageChanged (object src, EventArgs e)
{
// AspNetPager1.CurrentPageIndex = e. NewPageIndex;
BindNewsDatalist ();
}