Asp.net uses aspnetpager as the DataList page

Source: Internet
Author: User

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 ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.