4
Answers

GridView selected row index problem

Shareb

Shareb

15y
15.5k
1
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

 Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
GridView1.RowDeleting

        Dim index As Integer = 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)

    End Sub
Thanks in advance.
Answers (4)