Datagrid is not refreshing after postback

Discussion in 'ASP .Net Datagrid Control' started by Kreebog, Feb 25, 2004.

  1. Kreebog

    Kreebog Guest

    This problem shows up whenever I do any kind of update to the Access 2000
    database - the update (delete, update, insert) works fine and the database
    is updated, but the Datagrid does not reflect the changes until the page is
    reloaded again.

    The problem does not occur if I have insert a breakpoint between the
    database update and the function that re-binds the grid, which makes me
    wonder the application is somehow querying the database before the update
    completes executing, but with Access I'm not sure if I could prove or
    disprove that.

    Any ideas or suggestions?

    Thanks!
     
    Kreebog, Feb 25, 2004
    #1
    1. Advertising

  2. Your code should look something like this:

    .... In the DataGrid's UpdateCommand event handler ...

    Open Connection to Database
    Issue UPDATE
    Close Connection to Database

    Open Connection to Database
    Issue SELECT to get Data
    Rebind data to DataGrid
    Close Connection to Database

    .......................................................


    I'd wager you're not closing the connection between when you're issuing
    the UPDATE and rebinding the data to the DataGrid, OR you're not rebinding
    the data to the DataGrid at all after UPDATE...

    Happy Programming!

    --


    <shamelessPlug>
    For more information on the DataGrid, DataList, and Repeater controls,
    consider picking up a copy of my book:

    ASP.NET Data Web Controls
    http://www.amazon.com/exec/obidos/ASIN/0672325012/4guysfromrollaco
    </shamelessPlug>

    --

    Scott Mitchell

    http://www.4GuysFromRolla.com
    http://www.ASPFAQs.com
    http://www.ASPMessageboard.com

    * When you think ASP, think 4GuysFromRolla.com!




    "Kreebog" <> wrote in message
    news:u1T8$T2%...
    > This problem shows up whenever I do any kind of update to the Access

    2000
    > database - the update (delete, update, insert) works fine and the

    database
    > is updated, but the Datagrid does not reflect the changes until the page

    is
    > reloaded again.
    >
    > The problem does not occur if I have insert a breakpoint between the
    > database update and the function that re-binds the grid, which makes me
    > wonder the application is somehow querying the database before the

    update
    > completes executing, but with Access I'm not sure if I could prove or
    > disprove that.
    >
    > Any ideas or suggestions?
    >
    > Thanks!
    >
    >
     
    Scott Mitchell [MVP], Feb 25, 2004
    #2
    1. Advertising

  3. Kreebog

    Kostia Guest

    I had similar problem. I think both of as rely on DataGrid to do the
    connection staff and fill.
    I added sqlDataAdapter1.Fill(myDataSet); to Update handler and correct
    (updated) values appear in the columns.

    sqlConnection1.Open();
    System.Data.SqlClient.SqlCommand command = new
    System.Data.SqlClient.SqlCommand();
    command.CommandText = cmd;
    command.Connection = sqlConnection1;
    command.ExecuteNonQuery();
    // Rebind the data source to refresh the DataGrid control.
    sqlConnection1.Close();
    sqlDataAdapter1.Fill(myDataSet);
    DataGrid1.EditItemIndex = -1;
    DataGrid1.DataBind();
     
    Kostia, Feb 26, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jade Seguin
    Replies:
    2
    Views:
    478
    Elad Volpin
    Aug 2, 2004
  2. Replies:
    0
    Views:
    350
  3. gce
    Replies:
    2
    Views:
    1,718
  4. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    460
    =?Utf-8?B?Y2xpY2tvbg==?=
    Aug 4, 2006
  5. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    189
    Harlan Messinger
    Aug 3, 2006
Loading...

Share This Page