gridview cancel

The custom gridview buttons let a user edit/update/delete/cancel etc.....

Is it possible to cancel the edit through a indepent button.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David RobitailleAnalyst ProgrammerCommented:
set  CommandName="cancel"  and CausesValidation="False"
Mr_ShawAuthor Commented:
Do you mean

 <asp:Button ID="cancel_record_button" runat="server" CausesValidation="False"
                        CommandName="cancel" onclick="cancel_record_button_Click"
                        Text="Cancel" Visible="False" Width="78px" />
David RobitailleAnalyst ProgrammerCommented:
yes, but onclick="cancel_record_button_Click" is necesarry only if you do stuff in the cancel_record_button_Click. even. the  CommandName="cancel" should do the job.
There is also a event in the gridview "RowCancelingEdit" that will be run on cancel command event so you could put you code here if you want. thare is The row RowCommand that sould be raise on any command.
 CausesValidation="False" part allow post back event if there is some errors in a validator.
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

David RobitailleAnalyst ProgrammerCommented:
you could alos set the gridview.EditIndex = -1 in the cancel_record_button_Click event.
that will do the same job has the CommandName="cancel".
Mr_ShawAuthor Commented:
I have tried using CommandName="cancel" but nothing happens
David RobitailleAnalyst ProgrammerCommented:
where did you put the button?
does the RowCommand event raised?
did you set CausesValidation="False"  ?
Mr_ShawAuthor Commented:
No the RowCommand is not raised
David RobitailleAnalyst ProgrammerCommented:
the row command should be rised.
what do you mead by independant button?
if you are speaking of a button that is outside of the gridview then :
  1. remove all we talked about
  2. <asp:Button ID="cancel_record_button" runat="server" CausesValidation="False"
                            Text="Cancel" Visible="False" Width="78px" />
  3. in the cancel_record_button_Click event, set the gridview.EditIndex = -1
i dont know why you put Visible="False", did you toggle visibility in your code?
Mr_ShawAuthor Commented:
you are right that this is a button outside of the gridview.

This button only become visible when the user clicks the edit button inside the gridview...It is a long story, but in short this is how my interface needs to be!

Anyway, i tried putting gridview.EditIndex = -1  inside my cancel_record_button_Click  but nothing happens. The gridview remains in the editing state.
David RobitailleAnalyst ProgrammerCommented:
sorry, i forgot to say you have to call gridview.databind() to "refresh" the gridview after setting gridview.EditIndex = -1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mr_ShawAuthor Commented:
it is all crack..

I had to rebind the data.
David RobitailleAnalyst ProgrammerCommented:
Thanks for the grade and i`m glad i could help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.