2011-01-19 29 views
0

我在我的asp.net webform中有gridview。錯誤在gridview時allowPaging = true - asp.net

我結合我的數據庫的GridView這樣的:

SQL = "SELECT id,Fname,Lname FROM MEN"; 
dsView = new DataSet(); 
adp = new SqlDataAdapter(SQL, Conn); 
adp.Fill(dsView, "MEN"); 
adp.Dispose(); 
GridView1.DataSource = dsView.Tables[0].DefaultView; 
GridView1.DataBind(); 

,這我把在GridView:allowPaging = true

其顯示的數據網格,但如果我按到第2頁.. 3 ..

,我得到這個錯誤:

The GridView 'GridView1' fired event PageIndexChanging which wasn't handled. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: The GridView 'GridView1' fired event PageIndexChanging which wasn't handled. 

在此先感謝

回答

4

您必須處理PageIndexChanging事件,如果您單擊設計器上的網格並查看事件,請雙擊PageIndexChanging事件,如果您不需要取消或執行任何特殊操作,只需重新綁定數據在GridView1_PageIndexChanging事件的處理

+0

謝謝!我嘗試它,沒有錯誤,但如何顯示下一個10 ... 20 ....記錄? – Gali 2011-01-19 18:33:50

1

您必須爲PageIndexChanging提供一個事件處理程序,它是您提供分頁邏輯的地方。

0

這樣寫:

GridView1.PageIndex = e.NewPageIndex; 

然後重新綁定網格。 你的問題將解決。

3

您應該添加命名空間

using System.Collections.Generic;

,寫這個代碼只

public void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 
    GridView1.PageIndex = e.NewPageIndex; 
    BindGridview(); 
} 

它100%的作品嚐試一下......

相關問題