Value of label in gridview when checkbox is checked

I have a gridview with a checkbox field. I am looping through the gridview to get all rows that the checkbox is checked. I then am wanting to insert those items into one table in a database and then update the table that the items were pulled from. I am able to insert the items that are checked, but am I having problems updating the one table. I have one column in the gridview that is a label holding the primary key. This field is not visible. How do I pull the value of this label so I can use it in my update statement. Here is the code I currently have:

Dim rowCollection As GridViewRowCollection = gvItems.Rows

For Each gridRow As GridViewRow In rowCollection

Dim ctl As Control = gridRow.FindControl("CheckBox1")
If TypeOf ctl Is System.Web.UI.WebControls.CheckBox Then

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Here is what I did . I added on selectedindexchanged to my gridview. I then added the following code to Sub gvITems_SelectedIndexChanged: index = gvItems.SelectedIndex
prmkey = gvItems.DataKeys(index).Value.ToString().

It works except for one problem. What I have is a gridview with a checkbox field. You check all the check boxes that you want to add to a form. After you have made your selections, you click a submit button. I then use a For Each loop to get all of the items checked and they are inserted into a new table and the table that populated the gridview is updated.

Now when I click the submit button it only adds the first row in the gridview to the new table whether I have checked it or not. Not sure what I need to do next to fix this.
Thanks

I had not used it before, this is the method I've used because I've seen other people use it. It works.
And from what I've seen of the code here, it'd be lightning to implement. Albeit, the datakeys is probably the better way to go, that way your transmitting one less column of html and viewstate.

I do have a datakey assigned to the grid. I have the onselectedindexchanged event. Where I am confused is to what event do I need to use. I am looping through the rows to find all checked rows and for each row checked I am updating and inserting into the tables.

>> I have the onselectedindexchanged event. Where I am confused is to what event do I need to use. I am looping through the rows to find all checked rows and for each row checked I am updating and inserting into the tables.

If you use onselectindexchanged, then *every time* the selected gridview row changes, your code is firing and it is looping through the grid and doing this insert routine you posted.

From what it sounds like, that's not what you want....it looks like you could just put a "Update" button on your page and put the code in the button clicked event...

Featured Post

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this?
(CODE)
In .NET 3.5, this is possible…

This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so.
This will be demonstrated using Adobe Premiere Pro CS6.

Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…