日期:2014-05-18  浏览次数:20589 次

母板页中chechbox全选的问题
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="sendmsg.aspx.cs" Inherits="send_sendmsg" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>无标题页</title>
  <style type="text/css">
  .style1
  {
  width: 80%;
  }
  </style>
</head>

  <script language="javascript" type="text/javascript">
function selectAll(ctlName,bool)
{
  var ctl = document.getElementById(ctlName);//根据控件的在客户端所呈现的ID获取控件
  var checkbox = ctl.getElementsByTagName('input');//获取该控件内标签为input的控件
  /*所有Button、TextBox、CheckBox、RadioButton类型的服务器端控件在解释成Html控件后,都为<input type=''..../>,通过type区分它们的类型。*/
  for(var i=0;i<checkbox.length;i++)
  {
  if(checkbox[i].type=='checkbox')
  {
  checkbox[i].checked = bool;
  }
  }
}
  </script>
<body>
  <form id="form1" runat="server">
  <div>
   
  <asp:Image ID="Image1" runat="server" ImageUrl="~/img/3-1.jpg" />
   
  </div>
  <table class="style1">
  <tr>
  <td colspan="5">
  &nbsp;</td>
  </tr>
  <tr>
  <td colspan="5">
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
  DataSourceID="SqlDataSource1">
  <Columns>
  <asp:TemplateField HeaderText="选择">
  <ItemTemplate>
  <asp:CheckBox ID="CheckBox1" runat="server" />
  </ItemTemplate>
  </asp:TemplateField>
  <asp:BoundField DataField="phone" HeaderText="phone" SortExpression="phone" />
  <asp:BoundField DataField="p_time" HeaderText="p_time" 
  SortExpression="p_time" />
  <asp:BoundField DataField="message" HeaderText="message" 
  SortExpression="message" />
  </Columns>
  </asp:GridView>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  ConnectionString="<%$ ConnectionStrings:.netConnectionString %>" 
  SelectCommand="SELECT [userid], [phone], [p_time], [message] FROM [userinfo]">
  </asp:SqlDataSource>
  </td>
  </tr>
  <tr>
  <td colspan="5">
  <asp:TextBox ID="TextBox1" runat="server" BorderColor="#6699FF" 
&