Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net Gridview Paging doesin't work inside UpdatePanel

Although, questions somehow similar to this have been asked for a number of times, but the question is still unsolved. Here is the question: I have a GridView which is contained in a tab container AJAX control which itself is inside an UpdatePanel. Gridview works excellent and its corresponding methods are fired accurately, but when I enable paging(e.g.) after I click on page 2, the GridView hides itself. here is my PageIndexChanging() method:

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;        
    GridView1.DataBind();
    UpdatePanel2.Update();        
}

Why paging causes GridView to stop working correctly? What can I do?

like image 230
Farshid Avatar asked Jan 26 '11 06:01

Farshid


2 Answers

The solution is that you should refill the dataset which is used to populate the gridview, each time your page index is changed. By this way, you could ensure that in each seperate postback which has been triggered by the gridview page number, results will be populated.

like image 172
Farshid Avatar answered Sep 19 '22 11:09

Farshid


I just tried that above code. I had same issue and now it is working just fine.

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 
    GridView1.PageIndex = e.NewPageIndex;         
    GridView1.DataBind(); 
    //  UpdatePanel2.Update();   <-- Remove this line from your code.
} 

I have GridView inside update panel. Did you write your event PageIndexChanging in your .aspx file also?

Hope this helps.

like image 45
Jay Avatar answered Sep 21 '22 11:09

Jay