Search code examples
c#asp.netgridviewupdatepanel

Checbox inside gridview within updatepanel


I have this Code,

  <asp:UpdatePanel runat="server">
    <ContentTemplate>   
        <asp:GridView ID="gvTestDetails" runat="server" AutoGenerateColumns="false" OnDataBound="gvTestDetails_DataBound" EnableModelValidation="true">    
            <Columns>
                <asp:TemplateField HeaderText="Select">
                    <ItemTemplate>
                        <asp:CheckBox ID="cbSelectRecord" runat="server" AutoPostBack="true"  OnCheckedChanged="cbSelectRecord_CheckedChanged"/>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

What I want is,When I check one of the CheckBox in Row of the GridView all other CheckBoxes get un-Checked.


Solution

  • Why dont you just use the Mutually Exclusive CheckBox from the Ajax Controll Toolkit ?

    Just add it below your CheckBox:

    <ajaxToolkit:MutuallyExclusiveCheckboxExtender runat="server"
        ID="RandomID"
        TargetControlID="cbSelectRecord" 
        Key="AllwaysSameID" />
    

    Note: You need to include a scriptmanager and AjaxControllToolkit in your project then. But this isnt bad because the AjaxControllToolkit offers alot of great stuff.