2011-11-28 79 views
0

在asp.net Web應用程序,我寫的代碼像這樣的DataList分頁:asp.net中的Datalist分頁?

PagDat = new PagedDataSource(); 
PagDat.AllowPaging = true; 
PagDat.PageSize = 10; 
PagDat.CurrentPageIndex = **currentpage**; 
PagDat.DataSource = ds.Tables[0].DefaultView; 
dtlstMagazine.DataSource = PagDat; 
dtlstMagazine.DataBind(); 

在這個「當前頁」是我聲明爲靜態整數一個varaible。我認爲這可能是衝突,當更多的用戶訪問此頁面我是對的嗎?

回答

1

是的你是對的。

您應該保存您的PageDataSouce page index in State Management object。使用靜態變量不適合用於此類頁面級操作的web 應用程序。

創建當前頁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; 
    } 
} 

檢查以下鏈接瞭解更多信息:
Adding Paging Support to the Repeater or DataList with the PagedDataSource Class

+0

謝謝NIRANJAN卡拉 –