Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm running into a strange issue. I'm trying to see what checkboxes are selected within the gridview. My code looks like it follows the examples I found on the internet, and works in FF & Chrome, but fails in IE9. In IE9, the checked property never returns true. I've stepped through the code, and have verified that it's looking at the correct checkbox, but IE will always return false.

Does anyone have any ideas? Below is my markup & codebehind.

ASP.NET
<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>


VB
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
Posted

Please check where is your grid load placed.. It should be outside the Ispostback.. other wise before executing your check box code.. it will load the Grid again.
 
Share this answer
 
Comments
TomCollins88 15-May-12 11:58am    
I'm not doing a postback.

Again, this works in Chrome & FF, just not in IE. Thanks.
OK, solved. My gridview wasn't inside my form tags. I guess IE didn't like that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900