Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delete row from gridview

Posted on 2008-10-16
5
Medium Priority
?
901 Views
Last Modified: 2013-11-27
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
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

Open in new window

0
Comment
Question by:ratkinso666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 2000 total points
ID: 22732774
Check if the value you are looking for is in e.Values array
Otherwise you can get the index of the deleting row as e.RowIndex, so when you say "gv.Rows[e.RowIndex];" you will get the deleting row from the grid view, you can get the value from the row.

Hope that helps
0
 

Author Comment

by:ratkinso666
ID: 22760194
Unfortunately, the only values I can find are for the SelectedValue...  If I Select a row and delete from another row, I am only seeing the the selected row's value.  I'm sure it must know the correct row to delete from somewhere, but I still don't see it???
0
 

Author Comment

by:ratkinso666
ID: 22760968
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...
0
 

Author Comment

by:ratkinso666
ID: 22780500
Here was the eventual solution:

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
        Dim i As Integer = e.RowIndex
        Dim BP_ID As String = GridView1.Rows(i).Cells(10).Text
0
 

Author Closing Comment

by:ratkinso666
ID: 31506807
Thank you very much for your help!!  Definitley got me on the right track.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question