Wednesday, August 11, 2010

ASP.NET question. Cancelling a delete in gridview.?

I've got a school problem where I have data showing in a gridview that is set to be deletable. I'm supposed to make one row NOT deletable. Where on earth would I code that and how?


ASP.NET question. Cancelling a delete in gridview.?
There are many ways of doing this. You can add javascript on that particular button to cancel the button click event.





This is probably the most striaght forwar way of doing it:





Try adding code in the RowDeleting event of the gridview.


(GridView_RowDeleting)





So, if that button is clicked then cancel the event:





Private Sub GridView_RowDeleting.....





If GridView.Rows(e.RowIndex).Cells(0).Text = RowID Then





e.Cancel = True





End If





End Sub





Also, if you're working in C#, sorry.ASP.NET question. Cancelling a delete in gridview.?
Easiest way would be to remove the delete button in the template, depending on if the row you needed to delete was part of a repeating set or not. If it IS part of a repeating set, then I'd need some more info to make figure that one out. If you just wanted to make the first row not deletable, you could set up something in the code behind to process the button code, and discern what row it was. You could do the same if you just wanted to make it not deletable based on the data that is entered. Processing a delete button in the code behind is relatively easy, you would just need to set up a procedure to get the control and command parameters.

No comments:

Post a Comment