cancel saving data in datagrid

C

Calvin

My datagrid cells are all editable textbox and attached onTextChanged event
so that every changes will be saved in the datatable on next postback. My
problem is if the cancel button is clicked instead of save button, i don't
want to do any validation and saving data to datatable but only just quit. I
can't do that now becuase the onTextChanged event runs before cancel button
click event. So, is there a way to solve it?
Thanks
 
J

Jim Nugent

I may be missing something but why not:
1. Disable validation for your cancel button (set the property "Causes
Validation" to false).
2. Save your data in the saveButton Click handler, rather than TextChanged.
That way if cancel is pressed, validation won't occur and changes won't be
saved. You can redirect to another page or whatever.
 
C

Calvin

My datagrid is editable which means all cells in all rows are textbox
instead of label. So, at any time, the data can be changed. When the field
is updated, OnTextChanged event fires and the data is saved to datatable
first. So, even I set the cancel button causes validation to false, the
OnTextChanged event still fires and so error occurs since the datatype
mis-matched from the datatable. I must have the OnTextChanged event,
otherwise all changed event may be lost on next postback.
 
J

Jim Nugent

There are a couple of ways around this I think.
The first one I KNOW works because we use it:
1. Have an edit linkbutton in the first column of your grid. In the
linkbutton command handler, grab the data and put up a different page with
that data in a text box and allow it to be edited. It's more elegant IMHO
anyway and allows you to have textboxes and dropdown lists, etc. if
appopriate for your grid columns. Have save and cancel available. Save (on
the "edit" page) updates that row of the table; cancel bails out without
firing the validator.

2. Let the grid edits modify your DataSet object (in memory), and save out
your DataSet to to the DB table at one in the save handler. Each row in your
ds has a RowChanged (or something like that) property so you can even get
efficient and only update the ones that need it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top