2011-08-19 83 views
1

大家好我有一個頁面,需要從一個SQL數據源的項目,並把它們放入一箇中繼器。我想知道如何改變pagedDatasource的頁面索引當我點擊另一個按鈕更改pageDataSource頁面

頁面加載

DataSourceSelectArguments arg = new DataSourceSelectArguments(); 

    arg.MaximumRows = 8; 
    arg.AddSupportedCapabilities(DataSourceCapabilities.Page); 



    DataView set = (DataView)SQLDataSourceProducts.Select(arg); 
    int rows = arg.TotalRowCount; 
    PagedDataSource paged = new PagedDataSource(); 
    paged.DataSource = set; 
    paged.AllowPaging = true; 
    paged.PageSize = 3; 
    int pageIndex = 1; 
    paged.CurrentPageIndex = pageIndex - 1; 

    RepeaterProducts.DataSource = paged; 
    RepeaterProducts.DataBind(); 

上的按鈕按下

protected void moreButton_Click(object sender, EventArgs e) 
{ 
    //Change the pageIndex 

} 

感謝所有

回答

1

大家好找到了答案,這就是我對任何想要知道的人做的事

public void popRepeater() 
{ 
    //Clear datasource so you can repopulate without getting duplication error 
    SQLDataSourceProducts.SelectParameters.Clear(); 

    //Your query 
    SQLDataSourceProducts.SelectParameters.Add 


    DataSourceSelectArguments arg = new DataSourceSelectArguments(); 

    arg.MaximumRows = 8; 
    arg.AddSupportedCapabilities(DataSourceCapabilities.Page); 



    DataView set = (DataView)SQLDataSourceProducts.Select(arg); 
    int rows = arg.TotalRowCount; 
    PagedDataSource paged = new PagedDataSource(); 

    paged.DataSource = set; 
    paged.AllowPaging = true; 
    paged.PageSize = 3; 
    //int pageIndex = 1; 
    paged.CurrentPageIndex = CurrentPage ; 

    RepeaterProducts.DataSource = paged; 
    RepeaterProducts.DataBind(); 
} 

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; 
    } 
} 

protected void moreButton_Click(object sender, EventArgs e) 
{ 

    CurrentPage += 1; 
    popRepeater(); 

}