ratkinso666
asked on
Delete row from gridview
Hi all, I have a gridview that deletes just as it should, but then in the code-behind I have it deleting from other tables, based on what you deleted from the gridview. This works FINE, BUT you MUST select the row from the gridview and THEN delete because of this line:
Dim BP_ID As String = GridView1.SelectedValue
I need that value, is there a way I can tell it something like DeletingValue or something, instead of the SelectedValue???
VS2005 VB.Net
Dim BP_ID As String = GridView1.SelectedValue
I need that value, is there a way I can tell it something like DeletingValue or something, instead of the SelectedValue???
VS2005 VB.Net
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Dim BP_ID As String = GridView1.SelectedValue
Dim BA_ID As String
Dim sql7 As String = "Select BA_ID from bomAuxEquip where BP_ID = @BP_ID"
Using conn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("HCISDataCARsConnectionString").ConnectionString)
Dim cmd As New SqlCommand(sql7, conn)
cmd.Parameters.AddWithValue("@BP_ID", BP_ID)
Dim reader As SqlClient.SqlDataReader
cmd.Connection.Open()
reader = cmd.ExecuteReader
reader.Read()
BA_ID = reader("BA_ID")
cmd.Connection.Close()
End Using
Dim sql17 As String = "DELETE FROM [bomSecAuxEquip] WHERE [BA_ID] = @BA_ID"
Using conn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("HCISDataCARsConnectionString").ConnectionString)
Dim cmd As New SqlCommand(sql17, conn)
cmd.Parameters.Add(New SqlParameter("@BA_ID", BA_ID))
conn.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
End Using
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Does anyone else know how I can get this value?? I MUST have it, as the users are deleting without selecting and when they do that, they delete the children from the selected row, rather from the row they wanted to delete from...
ASKER
Here was the eventual solution:
Protected Sub GridView1_RowDeleting(ByVa l sender As Object, ByVal e As System.Web.UI.WebControls. GridViewDe leteEventA rgs) Handles GridView1.RowDeleting
Dim i As Integer = e.RowIndex
Dim BP_ID As String = GridView1.Rows(i).Cells(10 ).Text
Protected Sub GridView1_RowDeleting(ByVa
Dim i As Integer = e.RowIndex
Dim BP_ID As String = GridView1.Rows(i).Cells(10
ASKER
Thank you very much for your help!! Definitley got me on the right track.
ASKER