Reputation: 30343
In asp.net Web application, i write code for datalist paging like this :
PagDat = new PagedDataSource();
PagDat.AllowPaging = true;
PagDat.PageSize = 10;
PagDat.CurrentPageIndex = **currentpage**;
PagDat.DataSource = ds.Tables[0].DefaultView;
dtlstMagazine.DataSource = PagDat;
dtlstMagazine.DataBind();
In this "currentpage" is a integer varaible which i declared as a static. I think it could be conflict when more user access this page am i right?
Upvotes: 0
Views: 1180
Reputation: 18260
Yes your are right.
You should Save your PageDataSouce
page index in State Management object
. using static variable is not a good approach in web application for such page level operations.
Create CurrentPage property
:
public int CurrentPage
{
get
{
// look for current page in ViewState
object o = this.ViewState["_CurrentPage"];
if (o == null)
return 0; // default page index of 0
else
return (int) o;
}
set
{
this.ViewState["_CurrentPage"] = value;
}
}
Check following link for more information:
Adding Paging Support to the Repeater or DataList with the PagedDataSource Class
Upvotes: 1