This is a migrated thread and some comments may be shown as answers.

cached dataset and edit mode

1 Answer 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mac
Top achievements
Rank 1
mac asked on 23 Apr 2010, 08:26 PM
hello
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.



1 Answer, 1 is accepted

Sort by
0
mac
Top achievements
Rank 1
answered on 23 Apr 2010, 09:53 PM
disregard.. the method to just update the cache/datatable is probably the simplest and most efficient method. Just extending the update to then update the datatable works fine.
ie
d = cache("thecache")  
if d is nothing  
bindgrid()  
d = cache("thecache")
end if  
for i as integer = 0 to d.rows.count-1  
if d.rows(i).Item("key") = pk then  
'update d.rows(i).item()  
exit for  
Next  
End if   
cache("thecache") = d  
end if 




Tags
Grid
Asked by
mac
Top achievements
Rank 1
Answers by
mac
Top achievements
Rank 1
Share this question
or