[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

Gridview inside UpdaePanel does not update

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
HandyManny
Asked:
HandyManny
  • 3
  • 3
2 Solutions
 
urir10Commented:
try including that for your update panel

  <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="updateBtn" EventName="Click" />
                     
   </Triggers>
0
 
HandyMannyAuthor Commented:
@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
 
urir10Commented:
do u have any other update panel as parents to that update panel?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
HandyMannyAuthor Commented:
@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
 
urir10Commented:
can u post the code for the button as well as the markup for the page?
0
 
HandyMannyAuthor Commented:
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now