Asp net rowupdating newvalues

Row Updating event, doesn’t work as all samples say it should do.All samples of course assume you’re doing everything in your page, but I have to do everything in my code-behind, because on forehand I don’t know what I’ll be binding to my Grid View.But for this demo, I’ll show you the simple version, that also doesn’t work 🙂Let’s bind the data to our Grid View and have it autogenerate our columns, as well as an edit button.

asp net rowupdating newvalues-58

As the values are inserted into an Ordered Dictionary - you can use the field names to access the changed data 2.

There are multiple ways in which one can get the data from the current row that is being edited in a Grid View. Using "Extract Values From Cell": This is an easy way to get all the values from the current row.

Otherwise missing cells will be nulled out by the auto update operation. The dictionary consists of the new values to be set on the row's unbound cells.

The hash key is the key of corresponding column and the value is the new value to be set.

Then we need to override the gridview's Row Updating event.

In this event you can write code to get the newvalue of checkbox's checked property only.

Please let me know if this has helped anyone solve the problem!!

By performing above coding we would avoid the error - Specified cast is invalid.

If we could have accessed the Bind method ,that implicitly performs two-way binding, in the code-behind then we could have just override the Row Databound event and assigned the value to the gridview's checkbox control using the Bind method.

But unfortunately the Bind is not available in ASP. We could still achieve this in two simple and easy steps. Wrap the Eval(fieldname) HTML code in a function eg: Checkvalue that checks the datafield value, performs transformations to True OR False values and assigns to Chekced property. Override the Row Updating event of gridview and update only the Checked property's value since the SQLData Source that is bound to gridview will take care of remaining fields to update.

This will lead to problems like "Grid View does not show updated values", "Grid View looses values changed by user". In your Page_load, this is typically only inside a block where you check to make sure that Page_Load is not being called during a post-back call.

Tags: , ,