2012-11-17 90 views
1

我一直在關於如何在另一個頁面中顯示我的網格數據。在GridView上尋呼

基本上我有一個GridView名稱「gdvRiders」並啓用了Paging。問題是當我點擊頁面2時,我得到一個沒有數據的空白頁面。有人能幫我嗎?我開始學習C#

這裏是我的代碼:

protected void Page_Load(object sender, EventArgs e) 
    { 
     DataBase db = new DataBase(true); 
     string strSQL; 
     DataTable dt; 

     if (!IsPostBack) 
     { 
      strSQL = "SELECT r.surname, r.firstname, cn.country, r.age, f.flagurl " + 
        "FROM (Riders r INNER JOIN par_CountryNation cn ON r.countryid = cn.countryid) INNER JOIN par_Flags f ON cn.flagid = f.flagid "; 

      dt = db.getDataTableAc(strSQL, "list_Riders"); 

      gdvRiders.DataSource = dt; 
      gdvRiders.DataBind(); 

     } 

    } 

    protected void gdvRiders_PageIndexChanging(object sender, GridViewPageEventArgs e) 
    { 
      gdvRiders.PageIndex = e.NewPageIndex; 
      gdvRiders.DataBind(); 

    } 
} 
+0

您不需要重置索引並重新綁定。 GridView分頁自動完成。 –

回答

1

需要assgin數據到數據源電網You should put the code to bind the gridview in separate function and call it from page_load and PageIndexChanging.

protected void gdvRiders_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{    
     strSQL = "SELECT r.surname, r.firstname, cn.country, r.age, f.flagurl " + 
       "FROM (Riders r INNER JOIN par_CountryNation cn ON r.countryid = cn.countryid) INNER JOIN par_Flags f ON cn.flagid = f.flagid "; 
     dt = db.getDataTableAc(strSQL, "list_Riders"); 
     gdvRiders.PageIndex = e.NewPageIndex; 
     gdvRiders.DataSource = dt; 
     gdvRiders.DataBind(); 

} 
+0

明白了......非常感謝您的快速回復。 – user1832038