Best place to cancel delete

D

David C

I have a GridView with a Delete link and wondered where the best place was
to check and cancel delete of a row/record that is bound to an
SqlDatasource. I can use datasource Deleting event or GridView_RowDeleting
event. I need to get 2 values from the row I am trying to delete so I can
perform another function returns whether I can delete the record or not. I
am trying to do this in gridview event (see code below) but it is not
working. Neither string is returning a value from the 2 cells. Can anyone
point out what I am doing wrong? Thanks.

David

Sub SubfilesGridView_RowDeleting(ByVal sender As Object, ByVal e As
GridViewDeleteEventArgs)

Dim strTextReturned As String


' Get the subfile of the record being deleted.

Dim row As GridViewRow = SubfilesGridView.Rows(e.RowIndex)


'Set value of new Subfile text from cell

'Subfile text is contained in the 3rd column (index 2).


Dim strsubfile As String = row.Cells(2).Text

'Set value of SeqNo from cell

'SeqNo is contained in the 2nd column (index 1).

Dim strseqno As String = row.Cells(1).Text


'Run function in DBClass module to delete network subfile folder

strTextReturned = DBClass.DeleteSubfolders(strseqno, strsubfile,
CLng(txtFileNumber.Text))

If Left(strTextReturned, 5) = "Error" Then

'There were files in the subdirectory or a runtime error occurred

'so cancel the delete of GridView row.

e.Cancel = True

End If

txtMsg.Text = strTextReturned

txtMsg.Visible = True

MultiView1.ActiveViewIndex = 0


End Sub
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top