Ti passo un po' di codice. Sono due esempi un poco diversi ma che fanno la stessa cosa. Cioè cercaco tutti i checkbox selezionati in una griglia. A te il compito di adattarli.
codice:
<asp:CheckBox Runat="server"></asp:CheckBox>
Private Function ChiaveSelezionate$()
Dim cb As CheckBox
Dim dgi As DataGridItem
Dim id$ = ""
For Each dgi In Me.DataGrid1.Items
cb = CType(dgi.Cells(15).Controls(1), CheckBox)
If cb.Checked Then
id &= "," & (dgi.Cells(0).Text)
End If
Next
If (id.Length > 0) Then
id = id.Substring(1)
End If
Return id
End Function
<asp:CheckBox ID="chkSelect" Runat="server" ></asp:CheckBox>
Private Sub btnEval_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEval.Click
Dim TotalPrice@
Dim Count%
Dim dgi As DataGridItem
For Each dgi In Me.DataGrid1.Items
'ricava il riferimento ai checkbox nella riga
Dim cb As CheckBox = DirectCast(dgi.FindControl("chkselect"), CheckBox)
'se selezionato ricava il prezzo e lo aggiunge al totale
If cb.Checked Then
'recupera l'id, chiave di questa riga
Dim id$ = Me.DataGrid1.DataKeys(dgi.ItemIndex).ToString
'seleziona la riga nel datatable per questa chiave
Dim dr As DataRow = GetDataRow(id)
If Not dr.IsNull("price") Then
'aggiunge il prezzo al totale corrente
TotalPrice += CDec(dr("price"))
Count += 1
End If
End If
Me.Label1.Text = String.Format("Total price for {0} selected books is E {1:#,##0.00}", Count, TotalPrice)
Next
End Sub
Si potrebbe fare anche meglio utilizzando un checkbox html dentro la griglia con name identico a tutti e value = ID