Gridview中的复选框使用IE浏览器

时间:2012-05-14 20:49:00

标签: asp.net internet-explorer gridview checkbox

我遇到了一个奇怪的问题。我正在尝试查看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

1 个答案:

答案 0 :(得分:1)

好的,解决了。我的gridview不在我的表单标签内。我猜IE不喜欢那样。