i got error on gridview in allowPaging = true - asp.net
-
hi 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: 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. thanks in advance
-
hi 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: 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. thanks in advance
It's telling you exactly what the probelm is: you have not created the PageIndexChanging event and handled it which is what you need to do unless you use one of the built in data sources that will give you paging and sorting for free. In design view, click on the grid, and view the event properties. Double-Click on the appropriate row and the method will be created for you. Now handle the event.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me
-
hi 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: 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. thanks in advance
Gali1978 wrote:
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.
Write a method for binding of Gridview
Private void BindGridView()
{
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();
}You Need Handle Gridview_pageIndexing event of GridView like this.
GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGridView();
}OR After First Retrial of Data -- Put The DataSet into ViewState Or Session.(Here also Gridview1_PageIndexChanging event is Required. In this event bind the gridview with DataSet(i.e DataSet from ViewState or Session)) See This Link Gridview in ASP.NET 2.0[^] I hope you issue will clear. Try this, Post here if you face any problem.
-
Gali1978 wrote:
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.
Write a method for binding of Gridview
Private void BindGridView()
{
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();
}You Need Handle Gridview_pageIndexing event of GridView like this.
GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGridView();
}OR After First Retrial of Data -- Put The DataSet into ViewState Or Session.(Here also Gridview1_PageIndexChanging event is Required. In this event bind the gridview with DataSet(i.e DataSet from ViewState or Session)) See This Link Gridview in ASP.NET 2.0[^] I hope you issue will clear. Try this, Post here if you face any problem.
-
Gali1978 wrote:
but I constantly see the same records, why ?
May be several reasons(Not exactly) .like Table contains duplicate rows (just check it once), Check Gridview Pager Settings (Page Size, Paging Modes). If you post your modified code here, i will check it.
-
try this.
protected void GridView1\_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; } protected void GridView1\_PageIndexChanged(object sender, EventArgs e) { GridView1.DataBind(); }
suchita