Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid is not refreshing after postback

Reply
Thread Tools

Datagrid is not refreshing after postback

 
 
Kreebog
Guest
Posts: n/a
 
      02-25-2004
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!


 
Reply With Quote
 
 
 
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      02-25-2004
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/AS...uysfromrollaco
</shamelessPlug>

--

Scott Mitchell
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

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




"Kreebog" <(E-Mail Removed)> wrote in message
news:u1T8$T2%(E-Mail Removed)...
> 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!
>
>



 
Reply With Quote
 
 
 
 
Kostia
Guest
Posts: n/a
 
      02-26-2004
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();
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Self-refreshing and non-self-refreshing controls Harlan Messinger ASP .Net 1 08-04-2006 01:13 PM
Self-refreshing and non-self-refreshing controls Harlan Messinger ASP .Net Web Controls 0 08-03-2006 12:29 PM
postback and refreshing. Steve H. ASP .Net 1 10-20-2005 02:26 PM
Can I raise a postback ? Session variable only visible after postback. Please help gce ASP .Net 2 05-08-2005 05:55 AM
Postback problem - datagrid not refreshing b_naick@yahoo.ca ASP .Net 0 01-20-2005 07:05 PM



Advertisments