benjamin54
benjamin54

Reputation: 1300

Issue with getting correct state of the checkbox in gridview

I have a nested gridview. In inner gridview, I have a column that contains checkboxes one per each row.

<asp:GridView ID="OuterGridView" runat="server" Width="80%" AutoGenerateColumns="false"
DataKeyNames="PartnerID,PromotionId" CssClass="GridViewCss">
<Columns>
    <asp:TemplateField HeaderText="Header1" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left"
        ItemStyle-Width="20%">
        <ItemTemplate>
            <asp:LinkButton ID="Edit" Text='<%#Eval("Org") %>'
                runat="server"></asp:LinkButton>
            <img alt="" style="cursor: pointer" src="images/ex.gif" />
            <div style="overflow: scroll; display: none; height: 100px;">
                <asp:GridView ID="InnerGridView" runat="server" AutoGenerateColumns="false"
                   ShowHeader="false">
                    <Columns>
                        <asp:TemplateField ItemStyle-HorizontalAlign="Left">
                            <ItemTemplate>
                                <asp:CheckBox Text='<%#Eval("School") %>'
                                    ID="CheckBoxInner" Checked='<%#Eval("IsActive") %>' runat="server"
                                    ViewStateMode="Enabled" EnableViewState="true" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Header2" HeaderStyle-HorizontalAlign="Left"
        ItemStyle-HorizontalAlign="Left" ItemStyle-Width="30%">
        <ItemTemplate>
            <asp:CheckBox Text="All" ID="CheckBoxOuter" runat="server" OnCheckedChanged="GridViewOuterCheckedChange"
                AutoPostBack="true" EnableViewState="true" />
        </ItemTemplate>
    </asp:TemplateField>
</Columns>
</asp:GridView>

I bind the gridviews when !ispostback. When I check any of the inner checkboxes, and try to save with save button, in button click event, I get proper values for checkboxes. But if I uncheck any of the ckeckbox (with Checked=True), in save button click event for that particular checkbox; I get the checked value as True instead of False.

Upvotes: 0

Views: 205

Answers (1)

TechDo
TechDo

Reputation: 18629

Try binding the grid outside !ispostback.

Upvotes: 0

Related Questions