Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid not refreshing

Status
Not open for further replies.

DanX

Programmer
Jan 16, 2001
13
0
0
US
I load a datagrid by binding to a datareader. I visible-ize a panel with textboxes and fill with a record's data from a link on the datagrid. I save the edited data from the form and re-bind the grid. The dang data does does not show unless I refresh (re-posting) again. Yet, if I look in the database, the change is already there before the refresh. The re-binding is called after the data is written to the database so what's the deal? I tried turning off viewstate for the grid, setting the cache expiration to -1, re-directing back to the same page afterwards to re-load...Then I rebuilt the whole thing out of a repeater instead of a datagrid, figuring that all the extra stuff going on in the grid might be providing a place for the old data to cache. Get through with all that and yikes! - still wont refresh! Any ideas where to go with this?
 
Sounds a bit obvious I know but this could be something in the page load event which initialises the page overriding the second binding when you postback. When the page is refreshed the page load will use new data? and pick up the changes from the database. It's hard to tell without seeing the code but if this is the case then the Page.IsPostBack property can be used in the page load event to prevent the initalising code running every time the page is submitted.

Rob

------------------------------------

On with the dance! let joy be unconfined;
No sleep till morn, when Youth and Pleasure meet
To chase the glowing hours with flying feet.
-Byron

------------------------------------
 
Hmmm... would that it were obvious to this sham of a programmer. Here's some code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then bindTransactions()
btnCancel.Attributes.Item("onClick") = "javascript:window.history.back();return false;"
End Sub
Sub bindTransactions()
Dim oCT As New ChurchTavern()
Dim dtr As OleDbDataReader
dtr = oCT.dtrGetTransactions
dgrdTransactions.DataKeyField = "TransactionID"
dgrdTransactions.DataSource = dtr
dgrdTransactions.DataBind()
dtr.Close()
End Sub

and then, later,

Private Sub btnAddUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddUpdate.Click
Select Case btnAddUpdate.CommandArgument
Case "blankform"
pnlAddUpdate.Visible = True
txtTransactionID.Visible = False
ClearForm()
btnAddUpdate.Text = "Save New Transaction"
btnAddUpdate.CommandArgument = "savenew"
btnCancel.Visible = True
Case "savenew"
Dim oCT As New ChurchTavern()
oCT.InsertTransaction(txtSort.Text, txtTitle.Text, txtDescription.Text)
btnAddUpdate.Text = "Add New Transaction"
btnAddUpdate.CommandArgument = "blankform"
pnlAddUpdate.Visible = False
bindTransactions()
Case "saveedited"
TransactionUpdate()
btnAddUpdate.Text = "Add New Transaction"
btnAddUpdate.CommandArgument = "blankform"
pnlAddUpdate.Visible = False
bindTransactions()

End Select

The "ChurchTavern" bit is a separate page/class where I am keeping the data access stuff for the most part. Not sure I see how anything in page_load could be negating the databind routine called in the button subroutine. Could you explain? I mean, I wouldn't MIND if the initializing code ran on page load -- if that was the databind routine. It seems like something is cacheing somewhere but as I said, I shut off everything I could, even viewstate for the grid.
 
I am having the same kind of problem. A couple of things that I have done that don't seem to help: (To narrow the problem down)

1) Redirect back to the same page. Doesn't help.
2) Rebind the grid. Nope.
3) Drop the DB connection and reconnect and rebind. Nope.

It has been frustrating, that is for sure.

Chris
 
In my case it did turn out to be open connections. I was creating the datareader in a separate class file which did not have a destructor "close" method. Works fine now that I fixed that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top