Datagrid is not refreshing after postback

K

Kreebog

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!
 
S

Scott Mitchell [MVP]

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
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

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

Kostia

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();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top