Member Avatar for BasicBoy

I am trying to update a row in a Gridview control whilst it is in edit mode.
I am trying to extract the old data field values which have not changed during the edit process, but can't seem to find them, as the postback after clicking the edit button removes those values.
Any idea on how I can extract the values contained in the cells of a specific row before going into edit mode
Thanks

are you trying to get the values before the gridview switches to edit mode or do you need to get the values before applying any updates to to the data? Say you click edit, now you get some input controls, you change a couple of values, then click update. Are you wanting the old values before the edit or before the update?

Member Avatar for BasicBoy

I am not sure. I want the values of the unupdated fields for the same record.

Member Avatar for BasicBoy

I want the data from the edit controls before they are posted back and refilled with old data. After having edited them but before updating them.

Then you should be able to use the GridView's OnUpdating event. This event occurs just before the data is sent to the database to be updated. The method will look something like

protected void GridView_OnUpdating(object sender, GridViewUpdateEventArgs e)
{

}

in the code behind. The parameter "e" will have two properties that you should be able to use. One called NewValues and one called OldValues.

protected void GridView_OnUpdating(object sender, GridViewUpdateEventArgs e)
{
    string value = e.NewValues["column_name"].ToString(); // would get one of the updated values

    string old = e.OldValues["column_name"].ToString(); // would get the original value
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.