I have a GridView with a CheckBox on each row, but when i save the checked state it thinks all CheckBoxes are checked when only the first row is help please
<asp:GridView ID="gvStaff" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataSourceID="dsStaff" Style="z-index: 1; left: 4px; top: 37px; position: absolute; width: 296px" AllowPaging="True" PageSize="8" ShowHeaderWhenEmpty="True" DataKeyNames="Id" Height="20px">
<EmptyDataTemplate>
<div align="center">No records found.</div>
</EmptyDataTemplate>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelectCode" runat="server" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:BoundField DataField="StaffNo" HeaderText="StaffNo" SortExpression="StaffNo" Visible="False" />
<asp:BoundField DataField="fulln" HeaderText="Name" SortExpression="fulln">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
</Columns>
</asp:GridView>
Private Shared objALCode As New ArrayList()
Private Sub SaveCheckedStatesCode()
Dim rowIndex1 As Integer = -1
For Each row As GridViewRow In gvStaff.Rows
rowIndex1 = Convert.ToInt32(gvStaff.DataKeys(row.RowIndex).Value)
Dim isSelected1 As Boolean = CType(row.FindControl("chkSelectCode"), CheckBox).Checked
If ViewState("SELECTED_ROWSCode") IsNot Nothing Then
objALCode = CType(ViewState("SELECTED_ROWSCode"), ArrayList)
End If
If isSelected1 Then
If Not objALCode.Contains(rowIndex1) Then
objALCode.Add(rowIndex1)
End If
Else
objALCode.Remove(rowIndex1)
End If
Next row
If objALCode IsNot Nothing AndAlso objALCode.Count > 0 Then
ViewState("SELECTED_ROWSCode") = objALCode
End If
End Sub