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

Update KeyValues?

3 Answers 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manny Siddiqui
Top achievements
Rank 1
Manny Siddiqui asked on 21 Jan 2010, 06:03 PM
Hi,

I have a grid that is storing key values using the DataKeyName property on the MasterTableView.

<MasterTableView DataKeyNames="col1, col2, record_timestamp">

Special attention needs to be paid to the record_timestamp value stored in the grid. This value is used for concurrency control and needs to be updated whenever the correponding record is updated.

Consider the following scenario.

(1) Grid loads for the first time. Every row in the grid has the values stored in the DataKeyNames property.
(2) The user updates a drop-down which results in a partial post back to the server and that particular record is updated in the database. This update results in a new value for the record_timestamp.

I need to find a way to update the grid to have this update value for that particular row!

The following code snippet would provide some insight as to how I am coding the method.

Protected Sub ddlCountries_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)  
 
Try  
  Dim dropdown As DropDownList = DirectCast(sender, DropDownList)  
  Dim tc As GridTableCell = DirectCast(dropdown.Parent, GridTableCell)  
  Dim dataItem As GridDataItem = DirectCast(tc.Parent, GridDataItem)  
 
  col1Value = dataItem.GetDataKeyValue("col1")  
  col2Value = dataItem.GetDataKeyValue("col2")  
  recordtimestampValue = dataItem.GetDataKeyValue("record_timestamp")   
 
  ' Update the database and get the new timestamp value  
 
  ' Update the grid item to have the new timestamp value stored in the data keys ?????  
 
  Catch ex As Exception  
 
    ' handle error  
 
  Finally  
 
  End Try  
End Sub 

Thanks,
Manny

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 26 Jan 2010, 11:33 AM
Hello Manny,

After the update to the database, just call the grid's Rebind method.

Greetings,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Manny Siddiqui
Top achievements
Rank 1
answered on 26 Jan 2010, 01:42 PM
Hi Tsvetoslav

Thanks for answering the question.

I have been rebinding the grid, no problem, but I wanted to make the operation efficient by just updating the key values without having the grid to reload the data from the database (I am assuming rebidning would call NeedDataSource).
0
Tsvetoslav
Telerik team
answered on 27 Jan 2010, 12:13 PM
Hello Manny,

Thanks for the clarification. I understand your requirement, however, please, note that when RadGrid populates itself with data, it turns to the database, retrieves the data and constructs a DataTable object to which it binds itself. This DataTable object is afterwards used for the grid's filtering, sorting and other features. There is no problem to update just the table cell with the stamp in question without turning to the database, however, in this case you will leave the grid's rows out of synchrony with the underlying DataTable object. This is bound to make the mentioned grid's features not perform correctly.

I hope this information helps.

Greetings,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Manny Siddiqui
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Manny Siddiqui
Top achievements
Rank 1
Share this question
or