Solved

Gridview inside UpdaePanel does not update

Posted on 2010-08-30
6
419 Views
Last Modified: 2013-11-08
Hi
This is so simple yet difficult :)
Ihave the following
- updatePanel with UpdateMode="Conditional"
- Gridview inside the updatePanel with EnableSortingAndPagingCallbacks="True"  
- Button inside the updatePanel I called it updateBtn
- ScriptManager with EnablePartialRendering="True"

In the server side, at   protected void updateBtn_Click(object sender, EventArgs e) method
// execute query
Gridview.DataBind();
Gridview.SelectedIndex = -1;
updatePanel.Update();

The problem is: When I click the updateBtn button, The Gridview does not update, unless I click the button again or I click on a page number.

Q: How can I refresh a gridview using a button and an update panel
0
Comment
Question by:HandyManny
  • 3
  • 3
6 Comments
 
LVL 7

Expert Comment

by:urir10
ID: 33562420
try including that for your update panel

  <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="updateBtn" EventName="Click" />
                     
   </Triggers>
0
 

Author Comment

by:HandyManny
ID: 33562443
@urir10:
I have already included the button as a trigger.
The button is working, but the gridview does not refresh unless I click the button twice or I click on a page number.
0
 
LVL 7

Accepted Solution

by:
urir10 earned 500 total points
ID: 33562495
do u have any other update panel as parents to that update panel?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:HandyManny
ID: 33562521
@urir10: No
I am pretty sure that the problem is realted to the post back thing.
You see, when I click the button again, the gridview refreshed. The same thing happens when I click on a page number of the gridview.

But I cannot figure it out because I am not expert with asp.net page life cycle  
0
 
LVL 7

Assisted Solution

by:urir10
urir10 earned 500 total points
ID: 33562538
can u post the code for the button as well as the markup for the page?
0
 

Author Comment

by:HandyManny
ID: 33562695
Well Thank you very much.
When I tried to re-write the code into simple version, I found the mistake.
The reason was the following:
I forgot to clear the data source before I execute the query. So the gridview is updated. However, the new data are appended at the bottom of the data source. Then when there is a postback, the data source some how re-sorted itself and then the new data can be seen at the top .
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MailAddress in vb 4 29
Correct and Effective way to generate pdf files online via JavaScript or ASP.Net? 6 53
ASP.NET (VB) return a record 2 35
Wordpress Query 5 25
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question