Update KeyValues?

4 posts, 0 answers
  1. Manny Siddiqui
    Manny Siddiqui avatar
    13 posts
    Member since:
    Jan 2010

    Posted 21 Jan 2010 Link to this post

    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

  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 26 Jan 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Manny Siddiqui
    Manny Siddiqui avatar
    13 posts
    Member since:
    Jan 2010

    Posted 26 Jan 2010 Link to this post

    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).
  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 27 Jan 2010 Link to this post

    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.
Back to Top