I'm having problem with code that I originally obtained from:
http://support.microsoft.com/default.aspx?scid=kb;...
This code is supposed to loop through datagrid rows and determine which rows
have cell18, a checkbox, selected. When I run this code it is erroring out
at line: "DataGrid1.DataKeys(DemoGridItem.ItemIndex)". After placing a watch
on the code it shows that .ItemIndex has a constant value of 0. What is
going wrong here and how can I fix it? Thanks.
---------------------------------------------------------
Private Sub GetSelections_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles getSelections.Click
Dim rowCount As Integer = 0
Dim gridSelections As StringBuilder = New StringBuilder
'Loop through each DataGridItem, and determine which CheckBox
controls have been selected.
Dim DemoGridItem As DataGridItem
For Each DemoGridItem In DataGrid1.Items
Dim myCheckbox As CheckBox =
CType(DemoGridItem.Cells(18).Controls(1), CheckBox)
If myCheckbox.Checked = True Then
rowCount += 1
gridSelections.AppendFormat("The checkbox for {0} was
selected<br>", DataGrid1.DataKeys(DemoGridItem.ItemIndex).ToStrin g())
End If
Next
gridSelections.Append("<hr>")
gridSelections.AppendFormat("Total number selected is: {0}<br>",
rowCount.ToString())
ResultsInfo.Text = gridSelections.ToString()
End Sub
---------------------------------------------------------