The Checkbox in the template comumn needs to be ASP Checkbox
Make sure you have assigned the datakey to the grid
My comments follow --
' Walk the grid looking for selected rows
Dim i As Integer = 0 -- This is not needed
Dim cb As CheckBox
Dim dgi As DataGridItem
Dim MCode As Integer
Dim str As String
For Each dgi In dgMachines.Items
cb = CType(dgi.FindControl("chkDel"), CheckBox)
-- Check if cb is not nothing
If cb.Checked Then
' Determine the key of the selected record ...
MCode = CType(dgMachines.DataKeys(dgi.ItemIndex),
Integer) -- Use the Itemindex property
' ... get a pointer to the corresponding dataset record ...
str = str + MCode.ToString
End If
i += 1 -- Not needed
Next
-----Original Message-----
From: bounce-aspx_professional-1184710@p...
[mailto:bounce-aspx_professional-1184710@p...]On Behalf Of
artimahendra@s...
Sent: Tuesday, January 14, 2003 11:29 AM
To: ASPX_Professional
Subject: [aspx_professional] RE: Data Grid
nope - it is not working....
Pl check out the code :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
' Walk the grid looking for selected rows
Dim i As Integer = 0
Dim cb As CheckBox
Dim dgi As DataGridItem
Dim MCode As Integer
Dim str As String
For Each dgi In dgMachines.Items
cb = CType(dgi.FindControl("chkDel"), CheckBox)
If cb.Checked Then
' Determine the key of the selected record ...
MCode = CType(dgMachines.DataKeys(i), Integer)
' ... get a pointer to the corresponding dataset record ...
str = str + MCode.ToString
End If
i += 1
Next
End Sub
thanks