how to save gridview data statically without worrying of values loss

gal mor 141 Reputation points
2022-10-24T07:51:58.39+00:00

I was wondering if there is a way in which I can save gridview's data for example a row with columns:Id/name/date, as a static object/model, and when inserting new values, to access that saved data and compare values? like checking if name was changed and so on.. thanks!
my mission was originally to run different db queries so for that I had to check if NAME value for example was changed. I did it by comparing hiddenfield with currentvalue so it is working,
but I'd still rather find another "safer" way to do that (to access data before updating row. to access initial values )
any ideas and help will be appreciated!

Developer technologies | ASP.NET | Other
SQL Server | Other
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 30,206 Reputation points Microsoft External Staff
    2022-10-24T10:00:12.587+00:00

    Hi @gal mor ,
    If you have two tables, you can try to create a dynamic DataTable using that, save to ViewState. Get the DataTable from ViewState whenever it is updated.

     dt = new DataTable();  
     ViewState["Test"] = dt;  
     GridView1.DataSource = (DataTable)ViewState["Test"];  
     GridView1.DataBind();  
    ////////////////////////GridView1_RowUpdating  
     DataTable dt = (DataTable)ViewState["Test"];  
     string a =  dt.Rows[e.RowIndex].ItemArray[1].ToString();  
    

    253533-6.gif

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.