Update gridview without refreshing the page

14,468

Solution 1

    <asp:GridView ID="GridView1" runat="server" EnableViewState="false">
    </asp:GridView>

BY DOING enableviewstate=”false” we make sure we are seeing updated data.!

Solution 2

Try using an UpdatePanel

<asp:UpdatePanel ID="UpdtPnlForGrdVw" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView ...></asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

As we set UpdateMode to Conditional we mean that

We will be updating the content of the UpdtPnlForGrdVw manually.

After binding data to the gridview use

UpdtPnlForGrdVw.Update()

to update the contents of the updatepanel which in your condition will be the gridview.

You can also do this with JavaScript, check https://stackoverflow.com/a/6177348/647884, remember you won't need the opener in your case if you try the solution in the link.

Solution 3

Try following code:

 GridView1.DataBind();
Share:
14,468
Manthan Shah
Author by

Manthan Shah

Updated on November 22, 2022

Comments

  • Manthan Shah
    Manthan Shah over 1 year

    Right now i m redirecting to same page for showing updated values in grid view. but i want to do that staying on the same page.I am using List as DataSource and not any Database.

    • Tim Schmelter
      Tim Schmelter over 11 years
      Why don't you modify the DataSource of the GridView accordingly and call grid.DataBind(). Apart from that, show what you've tried.
    • Ravi Vanapalli
      Ravi Vanapalli over 11 years
      @manthan9311 please do up vote correct answers
  • Tim Schmelter
    Tim Schmelter over 11 years
    That is simply wrong. TRULY Understanding ViewState
  • V.J.
    V.J. over 11 years
    thanks. i was using collections so it was possible. but in case of database i should use updatepanel. thanks 4 correction. Tim.
  • Tim Schmelter
    Tim Schmelter over 11 years
    This is not even a comment (although it is a step in the right direction).
  • Tim Schmelter
    Tim Schmelter over 11 years
    OP hasn't mentioned that he wants to use ajax or that the flicker is the issue.
  • Adil Mammadov
    Adil Mammadov over 11 years
    But it can be helpful to someone else who will read this "comment" )
  • Bastardo
    Bastardo over 11 years
    @TimSchmelter Well Tim, you are right but it is still a solution isn't it? Plus I am just suggesting things he doesn't have to mention using ajax, right?
  • Admin
    Admin over 11 years
    How can we do paging when using gridview in updatepanel as it is not supported for details check following link : Update Panel Control