Saed Al Shaar Dev Tips and Tricks

.NET and SharePoint from a different angle!

Handling Delete Command in GridView

Hi Folks,

Here are how to handle the Delete Command in a GridView control.

Protected Sub GridView1_RowDeleted(sender As Object, e As System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles GridView1.RowDeleted

If (e.Exception Is Nothing) AndAlso e.AffectedRows.Equals(1) Then
lblMessage.Text = “Deleted sccessfully.”
ElseIf (TypeOf e.Exception Is SqlException) AndAlso DirectCast(e.Exception, SqlException).Number.Equals(547) Then
lblMessage.Text = “Referential integrity issue.”
e.ExceptionHandled = True
lblMessage.Text = “Cannot be deleted.”
e.ExceptionHandled = True
End If

End Sub

Happy programming!

Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: