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.