我遇到了一个奇怪的问题。我正在尝试查看在 gridview 中选择了哪些复选框。我的代码看起来像我在互联网上找到的示例,在 FF 和 Chrome 中工作,但在 IE9 中失败。在 IE9 中,checked 属性永远不会返回 true。我已经单步执行了代码,并验证了它正在查看正确的复选框,但 IE 将始终返回 false。
有没有人有任何想法?下面是我的标记和代码隐藏。
<asp:GridView ID="gvParts" runat="server"
AllowSorting="True" AutoGenerateColumns="False"
CellPadding="5" DataKeyNames="Rec_ID" DataSourceID="dsParts"
PageSize="50" Width="100%">
<Columns>
<asp:TemplateField HeaderText="Select">
<HeaderTemplate>
Select
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="75px" />
</asp:TemplateField>
<asp:BoundField DataField="Arcft_Make" HeaderText="Make"
SortExpression="Arcft_Make" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Arcft_Model" HeaderText="Model"
SortExpression="Arcft_Model" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Source_Name"
HeaderText="Source_Name"
SortExpression="Source_Name"
DataFormatString="{0:d}"
HtmlEncode="false">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Part_Number"
HeaderText="Part Number"
SortExpression="Part_Number" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Vendor_Part_Number"
HeaderText="Vendor Number"
SortExpression="Vendor_Part_Number" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Vendor_Name"
HeaderText="Vendor Name"
SortExpression="Vendor_Name" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Descr"
HeaderText="Description"
SortExpression="Descr">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle Width="300px" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Date_Added"
HeaderText="Date_Added"
SortExpression="Date_Added">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Rec_ID"
ReadOnly="True" Visible="False">
<ItemStyle Width="0px" />
</asp:BoundField>
<asp:CommandField ShowEditButton="True" />
</Columns>
<SelectedRowStyle BackColor="#FFFFCC" />
<AlternatingRowStyle BackColor="#CCFFFF" />
</asp:GridView>
`
和
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles btnAdd.Click
Dim Rec_IDs As New List(Of String)
Dim Rec_ID As Int32
Rec_IDs = Session("Rec_IDs")
For Each Row As GridViewRow In gvParts.Rows
If CType(Row.FindControl("chkSelect"), CheckBox).Checked Then
Rec_ID = gvParts.DataKeys(Row.RowIndex).Value
If Not Rec_IDs.Contains(Rec_ID) Then
Rec_IDs.Add(Rec_ID)
End If
CType(Row.FindControl("chkSelect"), CheckBox).Checked = False
End If
Next
Session("Rec_IDs") = Rec_IDs
lblCount.Text = String.Format("You have {0} records selected",
Rec_IDs.Count.ToString)
End Sub