Datalist paging-C # Article (. NET)

Source: Internet
Author: User
I use the following Code Why does datalist disappear when I flip pages?

Sqlconnection con = new sqlconnection (configurationsettings. appsettings ["exampaperdb"]);
Sqlcommand cmd = new sqlcommand (query. tostring (), con );
Sqldataadapter ADP = new sqldataadapter (CMD );
Dt = new datatable ();
ADP. Fill (DT );
If (Dt. Rows. Count! = 0)
{
Pageddatasource objpage = new pageddatasource ();
Objpage. datasource = DT. defaultview;
Objpage. allowpaging = true;
Objpage. pagesize = 6;
Int curpage;
If (request. querystring ["page"]! = NULL)
Curpage = convert. toint32 (request. querystring ["page"]);
Else
Curpage = 1;
Objpage. currentpageindex = CurPage-1;
Lblcurpage. Text = "Current page: page" + curpage. tostring () + "page ";
If (! Objpage. isfirstpage)
// Define the URL of the hyperlink "Previous Page" as the virtual path of the current execution page, and pass the index value on the next page
Lnkprev. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (CurPage-1 );
// If the current page is not the last page
If (! Objpage. islastpage)
// Define the URL of the "next page" hyperlink as the virtual path of the current execution page, and pass the index value on the next page
Lnknext. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (curpage + 1 );
Dlresultlist. datasource = objpage;
Dlresultlist. databind ();

Answer 1: No re-binding

Answer 2: Re-bind the datalist itemcommand.

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.