Shareb

Shareb

  • NA
  • 16
  • 0

GridView selected row index problem

Jul 28 2009 4:40 AM
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)