Using SQL2k environment and do not have SQLCacheDependancy running. I am loading my data via the conventional cache method
sub bindgrid() Dim d As DataTable = CType(Cache("MyCache"), Data.DataTable) |
If d Is Nothing Then |
d = functions.dt("Select top 100* from table") |
Cache.Insert("MyCache", d, Nothing, DateTime.Now.AddSeconds(30), TimeSpan.Zero) |
status.innerhtml = "data loaded from database" |
Else |
status.innerhtml = "Data loaded from cache" |
End If |
RadGrid1.DataSource = d end sub |
I am calling the sub from within the needdatasource event. so now the grid loads either cached or fresh data. I am handling paging via calling bindgrid() again and setting pageindex to newpageindex.
This works fine. When I go into edit mode and incorporate the GridEditableitem method and update the selected row this also works fine except that the cached data now no longer matches the updated data. until the cache is rebuilt or I manually remove the cache on updated.
If e.CommandName = "Update" Then |
Dim ei As GridEditableItem = TryCast(e.Item, GridEditableItem) |
Dim pk As String = ei.OwnerTableView.DataKeyValues(ei.ItemIndex)("keyid").ToString() |
Dim empid As String = TryCast(ei("Emp_ID").Controls(0), TextBox).Text |
Dim sql As String = "update table set emp_id = '" & empid & "' where keyid = " & pk |
functions.Scalar(sql) |
Cache.Remove("MyCache") 'If I don't kill the cache I end up with the old values. |
bindgrid() |
End If |
Do you have any method or trick to updating the grid to the new values without having to rebuild the cache? I suppose I could somehow extract the datatable from the cache, loop through the datatable, find the affected row, somehow update the column and reset the grid... but that seems pretty laborious.