在GridView外面加上一个checkbox
1<input id="Checkbox1" type="checkbox" title="Check/Uncheck All" onclick="SelectAllPassenger(this);" /> Check/Uncheck All
1<asp:GridView ID="GridViewPassenger" runat="server" AutoGenerateColumns="False" EmptyDataText="No Passengers" Width="100%">
2 <Columns>
3 <asp:TemplateField>
4 <ItemTemplate>
5 <input name="CheckboxPassenger" type="checkbox" value='<%#Eval("PassengerId") %>' />
6 </ItemTemplate>
7 </asp:TemplateField>
8 <asp:BoundField HeaderText="Pick Up" DataField="GetOn" />
9 <asp:BoundField HeaderText="Drop Off" DataField="GetOff" />
10 <asp:BoundField HeaderText="Name" DataField="Name" />
11 <asp:BoundField HeaderText="Mobile" DataField="Mobile" />
12 <asp:BoundField HeaderText="Email" DataField="Email" />
13 </Columns>
14 </asp:GridView>
2 <Columns>
3 <asp:TemplateField>
4 <ItemTemplate>
5 <input name="CheckboxPassenger" type="checkbox" value='<%#Eval("PassengerId") %>' />
6 </ItemTemplate>
7 </asp:TemplateField>
8 <asp:BoundField HeaderText="Pick Up" DataField="GetOn" />
9 <asp:BoundField HeaderText="Drop Off" DataField="GetOff" />
10 <asp:BoundField HeaderText="Name" DataField="Name" />
11 <asp:BoundField HeaderText="Mobile" DataField="Mobile" />
12 <asp:BoundField HeaderText="Email" DataField="Email" />
13 </Columns>
14 </asp:GridView>
1<script language="javascript">
2unction SelectAllPassenger(chkall)
3 {
4 //get reference of GridView control
5 var grid = document.getElementById("<%= GridViewPassenger.ClientID %>");
6 var inputs = grid.getElementsByTagName("input");
7
8 for (var i=0; i<inputs.length; i++)
9 {
10 //if childNode type is CheckBox
11 if (inputs[i].type =="checkbox" && inputs[i].disabled == false)
12 {
13 //assign the status of the Select All checkbox to the cell checkbox within the grid
14 inputs[i].checked = chkall.checked;
15 }
16 }
17 }
18 </script>
2unction SelectAllPassenger(chkall)
3 {
4 //get reference of GridView control
5 var grid = document.getElementById("<%= GridViewPassenger.ClientID %>");
6 var inputs = grid.getElementsByTagName("input");
7
8 for (var i=0; i<inputs.length; i++)
9 {
10 //if childNode type is CheckBox
11 if (inputs[i].type =="checkbox" && inputs[i].disabled == false)
12 {
13 //assign the status of the Select All checkbox to the cell checkbox within the grid
14 inputs[i].checked = chkall.checked;
15 }
16 }
17 }
18 </script>