Hi, I have a GridView that is representing a DataSet in the a Session variable.
How can I get the GridView's selected row index from RowDeleting event handler?
or delete a row from the DataSet in the session in the RowDeleting event?
I want to do the following but the selected index is -1
VB.NET
ProtectedSub GridView1_RowDeleting(ByVal sender AsObject, ByVal e As
System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
GridView1.RowDeleting
Dim index AsInteger = GridView1.SelectedIndex
' Get the currently selected row using the SelectedRow property.Dim ds As DataSet = Session("TransferTo")
Dim dt As DataTable = ds.Tables("Transfer_To")
dt.Rows(index).Delete()
GridView1.DeleteRow(index)
EndSub
Thanks in advance.
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Shareb16 reputationPosted Jul 28, 2009, 5:51 AM EDT
0
Thanks for your reply but this throws ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Gaurish Kumar108 reputationPosted Jul 28, 2009, 7:48 PM EDT
for RowDeleting event you can get the row index with e.RowIndex
and on deleting event if you want to get the row, try this
GridView1.Rows[e.RowIndex]
Gaurish Kumar108 reputationPosted Jul 28, 2009, 1:13 AM EDT
Try this for find out the selectedindex of the grid
Shareb16 reputationPosted Jul 28, 2009, 5:51 AM EDT
Shareb16 reputationPosted Jul 28, 2009, 8:10 PM EDT
Now it's solved.