Search code examples
vb.netgridviewmessagebox

Get input parameter value for gridview delete (enable)


I've been stuck on a message box problem most of the day. I've populated a gridview with values. I've enabled Delete on the gridview and I have been successfully deleting through my stored procedure defined in the GridView Configurations (yay!). The problem that I am having is the user wants a MessageBox to appear after a row is deleted to let them know that the delete was successful and have a value from that particular row to appear in the message box - i.e. "Record ABC was successfully deleted!". No matter where I put the code, I can't get the index of the row that was/is/will be deleted. I attempted to put the code in SelectedIndexChanged, SelectedIndexChanging, RowDeleting, RowDataBound.

Here is my code. It's very simple, and it is quite possible that I'm missing something, as I am new to VB.net and ASP.net.

Dim i As Integer
Dim CouponID As String

i = gvECouponEditor.SelectedIndex

CouponID = gvECouponEditor.Rows(i).Cells(1).Text.ToString()

Dim Answer As MsgBoxResult = MsgBox("You have successfully deleted the ECoupon = " + CouponID, MsgBoxStyle.MsgBoxSetForeground, "Delete Successful!")

When I use this code in SelectedIndexChanged(ing), it never touches it. When I use it anywhere else, it tells me that the index is out of bounds because it is = -1. Can anyone help me get the row index or the input parameter that I use for my stored procedure (only defined in ASP.net) so that I know which row has the "Delete" link pressed? I would appreciate any help that you can provide.

Thank you.


Solution

  • The RowDeleting event documentation shows an example that sounds a lot like what you're trying to do. In fact, you need to even do less than that example. You should assign an event handler to your grid's RowDeleting event and then in the event handler method display a simple Hello, World message.