Asp.net gridview paging

I have a grid that has 10 rows. I installed paging = trueandpageSize = 2

Now, when I try to navigate the page at the specified link, for example, 1, 2, 3, I get an error, for example, a need event pageIndexChanged.

I added this event, but I don’t understand what code should be added to this event to go to the next page, maintaining the state on each page?

Please let me know

+3
source share
1 answer

All you have to do is set the PageIndex parameter for the GridView to a new page and re-link the control.

protected void gridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  gridView1.PageIndex = e.NewPageIndex;
  BindGrid(); // this is whatever method you call to bind your data.
}

EDIT:

You should already have an event handler for the DataBound event in the GridView:

protected void GridView1_DataBound(object sender, EventArgs e)
{
    // lots of code here to do stuff with bound data.
}

" " :

protected void GridView1_DataBound(object sender, EventArgs e)
{
   BindGrid();
}

PageIndexChanging , , ( DataBound).

?

+1

Source: https://habr.com/ru/post/1762137/


All Articles