asp.net through Aspnetpager for DataList pagination _ Practical Tips

Source: Internet
Author: User
Foreground code:
Code
Copy Code code 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= "firstpagetext=" "Home"
Lastpagetext= "Last" nextpagetext= "next page" onpagechanged= "aspnetpager1_pagechanged"
Prevpagetext= "Previous" width= "100%" alwaysshow= "true" cssclass= "Anpager" >
</webdiyer:AspNetPager>
</div>

Background code:

Code
Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
if (!) IsPostBack)
{
bindnewsdatalist ();
}
}
//binding DataList data source
private void Bindnewsdatalist ()
{
Fjdws. Businesslogic.lnewsmanager Lnewsmanager = new Fjdws. Businesslogic.lnewsmanager ();
this. Aspnetpager1.recordcount = Lnewsmanager. FindAll (). Count;
PagedDataSource PDS = new PagedDataSource ();//define a PagedDataSource class to perform paging functionality
PDS. DataSource = Lnewsmanager. FindAll ();
PDS. AllowPaging = true;
PDS. CurrentPageIndex = aspnetpager1.currentpageindex-1;
PDS. PageSize = aspnetpager1.pagesize;
this. Newslist.datasource = PDS;
Newslist.databind ();
}
protected void Aspnetpager1_pagechanged (Object src, EventArgs e)
{
//aspnetpager1.currentpageindex = E.newpageindex;
Bindnewsdatalist ();
}

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.