≡ Menu

how to check all check boxes on gridview in asp.net using javascript

please paste the following code in your java script area

function CheckAllDataViewCheckBoxes( checkVal)

{ for(i = 0; i < document.forms[0].elements.length; i++)

{elm = document.forms[0].elements[i]if (elm.type == ‘checkbox’)


{elm.checked = checkVal }




and following line on the header for ur check boxes field in item tamplate of grid view

<input id=’chkAllItems’ type=’checkbox’ onclick=’CheckAllDataGridCheckBoxes(document.forms[0].chkAllItems.checked)’ />

all sample Grid View code is here

<asp:GridView ID=”grdMembers” AllowPaging=”true” AllowSorting=”true” runat=”server” Width=”100%” AutoGenerateColumns=”False” OnRowDataBound=”grdMembers_RowDataBound” CellPadding=”3″ >

<HeaderStyle Height=”25px” ></HeaderStyle>
<asp:TemplateField ItemStyle-HorizontalAlign=”Center” headerText=”<input id=’chkAllItems’ type=’checkbox’ onclick=’CheckAllDataViewCheckBoxes(document.forms[0].chkAllItems.checked)’ />” >
<input id=”RowSelectorUser” runat=”server” name=”RowSelectorUser” type=checkbox value='<%# Eval(“ItemId”) %>’ />


on run time when u click check box on gridview all check boxes checked or unchecked with it

{ 0 comments… add one }

Leave a Comment