Monday, April 11, 2011

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
Else
lblMessage.Text = "Cannot be deleted."
e.ExceptionHandled = True
End If

End Sub

Happy programming!
Saed

No comments:

Post a Comment