locked
Update display of a single gridview row after data changed, without rebinding? RRS feed

  • Question

  • User1733860820 posted

    With a gridview bound to a sqldatasource, I update a row using a formview on the same page; I don't edit in the gridview itself. I want to update the gridview row for the record just changed by the formview. I don't want to rebind the entire gridview because that invokes whatever sort is applied and the updated row might end up on a completely different page of the grid.

    So, is there a way to update the text that is displayed in a single row of a bound gridview control "in place" without refreshing the entire gridview? Something like, find the row in the gridview and update the text value for the column that has been changed?

    Monday, December 4, 2017 6:37 PM

Answers

All replies

  • User-1838255255 posted

    Hi sevi,

    According to your description and needs, this needs could be achieved through the following steps:

    1. Show the selected row value in the formview from the gridview(You could use textbox to replace the td in formview, then add a button to save data).

    Display (Show) GridView Selected Row in FormView control in ASP.Net using C# and VB.Net: 

    https://www.aspsnippets.com/Articles/Display-Show-GridView-Selected-Row-in-FormView-control-in-ASPNet-using-C-and-VBNet.aspx 

    2. You say don't want to refresh the entire page when load the new data, i think you could use jQuery AJAX to access data and load it without refresh page:

    Bind data to GridView with jQuery or JSON in ASP.Net: 

    https://www.aspsnippets.com/Articles/Bind-data-to-GridView-with-jQuery-or-JSON-in-ASPNet.aspx 

    Best Regards,

    Eric Du 

    Tuesday, December 5, 2017 2:30 AM
  • User1733860820 posted

    The first item you list is not an issue, I have that in place.

    For the second item, refreshing the grid, is there really no other way than to bind using jquery or json? That's going to be more than I wanted to do. No way to simply update the text in a single row?

    Tuesday, December 5, 2017 3:15 AM
  • User-1838255255 posted

    Hi sevi,

    According to your needs, i think you could this method, when you click update button in formview, update this record in the database, if update success, then return true or false from the code behind, if update success, find this line record, then replace the text. 

    Best Regards,

    Eric Du 

    Tuesday, December 12, 2017 9:58 AM
  • User1733860820 posted

    Eric, what I am looking for is the method of "replace the text". How does one do that? What you've done is to repeat what my goal is. I want to know how to implement the gridview text replacement, as my own experiments have not been successful.

    Tuesday, December 12, 2017 4:14 PM
  • User-1838255255 posted

    Hi sevi,

    According to your needs, you could use jquery to achieve this, the gridview will be read as table in browser, so you cold check this tutorial:

    Using Jquery, replace one row in table with a new one: 

    https://stackoverflow.com/questions/7517519/using-jquery-replace-one-row-in-table-with-a-new-one 

    Best Regards,

    Eric Du 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 14, 2017 11:39 AM