i have gridview in my asp.net webform.
i bind my database to gridview like this:
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();
and this i put in the gridview: allowPaging = true
its show the data in the grid, but if i press to page 2..3..
and i got this error:
Th开发者_JAVA技巧e 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.
thanks in advance
You have to handle the PageIndexChanging event, if you click the grid on the designer and look at the events, double click on the PageIndexChanging event, if you don't need to cancel or do anything special, just rebind the data in the handler
You Should just add the namespace
using System.Collections.Generic;
and write this code only
public void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGridview();
}
it 100% works try it......
You have to provide an event handler for PageIndexChanging, which is where you provide the paging logic.
write like this in GridView1_PageIndexChanging
event:
GridView1.PageIndex = e.NewPageIndex;
then again bind the grid. ur prob will solve.
精彩评论