Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

Delete row with different selected value in gridview

Hi all, I need to be able to delete a row, while another row is selected and know the value of the deleting row, so I can pass that on to a DTS package.  I can get the selected row value with .selectedvalue, but how do I get the key values for the row being deleted??  I have looked through everything and only see the selected row's value.

VS 2005 using VB.Net
0
ratkinso666
Asked:
ratkinso666
  • 3
  • 2
1 Solution
 
M3mph15Commented:
Hi,
How do you choose which row is to be deleted?
You can access any data in any row by using the row's and cell's index.
e.g. Dim s As String = GridView1.Rows(1).Cells(2).Text
0
 
ratkinso666Author Commented:
In a plain drag and drop gridview, with a sql database...  To choose which row is deleted you hit the delete button.  I am not creating it in code-behind.  If you hit the select button then you can get the "SelectedValue" of the gridview, I am needing to know how to get the deleting value of the gridview..  I have followed this through several times, if I hit select on the gridview and then I hit delete from a different row, it does indeed delete the row you want to, but I need to know the key value for THAT row, NOT the selected row.  I am trying to pass that parameter to a DTS package so that it can delete the associated data from other tables.  Right now, if you hit SELECT and then hit DELETE it will work fine because I have the selected value by the person hitting select, but I don't want them to have to hit SELECT first...  right now they keep just hitting delete and that will delete the row they want to delete, but then passes the selected rows value to my DTS package and deletes all the data associated with the SELECTED row and not the DELETE row...  please let me know if that doesn't make sense...
0
 
M3mph15Commented:
Ok i think i get what your saying. Try this. This will execute before the row is actually deleted:

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  'This will give you the index of the row being deleted
Dim s As String = GridView1.Rows(i).Cells(3).Text  'Using the index you can access the row and it's cells
'Then send value to your DTS package
End Sub
-M3mph15
0
 
ratkinso666Author Commented:
M3mph15, YES, that worked GREAT!!!
Thank you very much
0
 
ratkinso666Author Commented:
Thank you again for your excellent help!!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now