2009-08-10 4 views
0
Server Error in '/' Application. 
-------------------------------------------------------------------------------- 

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. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[HttpException (0x80004005): The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.] 
    System.Web.UI.WebControls.GridView.OnPageIndexChanging(GridViewPageEventArgs e) +1325594 
    System.Web.UI.WebControls.GridView.HandlePage(Int32 newPage) +86 
    System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +464 
    System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +207 
    System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565 




-------------------------------------------------------------------------------- 
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082 

при использовании этой функции и включить подкачку = истинныйРуководство DataBind в Gridview пейджинг

private void BindGrid(string sqlQuery, ref GridView gv) 
{ 
    SqlConnection sqlConnection = null; 
    try 
    { 
     sqlConnection = new SqlConnection(strConnect); 
     SqlCommand scom = new SqlCommand(sqlQuery, sqlConnection); 
     scom.CommandTimeout = 100; 
     sqlConnection.Open(); 
     SqlDataAdapter adapter = new SqlDataAdapter(scom); 
     DataTable dt = new DataTable(); 
     adapter.Fill(dt); 
     gv.DataSource = dt; 
     gv.DataBind(); 
    } 
    catch (Exception e) 
    { 
     Response.Write(e.Message); 
    } 
    finally 
    { 
     if (sqlConnection != null) sqlConnection.Close(); 
    } 
} 
+0

любому решить эту –

ответ

1

Добавить обработчик события PageIndexChanging.

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 
    GridView1.PageIndex = e.NewPageIndex; 
    ..... 
    ..... 
    GridView1.DataSource=dt; 
    GridView1.DataBind(); 
    } 
+0

защищен недействительным GridView1_PageIndexChanging (объект отправителя, GridViewPageEventArgs е) { GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); } Справа? –

+0

как справиться с этим событием? –

0

Попытка, этот код:

int newPagenumber = e.NewPageIndex; 
    GridView1.PageIndex = newPagenumber; 

    GridView1.DataSource = call the method that will fill ur dataset. 
    GridView1.DataBind(); 
+0

Вы должны добавить, где разместить этот код – Flo

Смежные вопросы