<%@ 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">
</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"
BorderStyle="Dotted" Columns="55" ForeColor="#6600FF" MaxLength="200" Rows="6"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
<asp:CheckBox Text="全选/反选" runat="server" ID="cbHead" onclick="javascript:selectAll('GridView1',this.checked);">
</asp:CheckBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="phone" HeaderText="123" SortExpression="phone" />
</Columns>
</asp:GridView>
</td>
<td>
</td>
</tr>
</table>
<p>
<asp:Button ID="Button4" runat="server" Text="Button"
onclick="Button4_Click" />
</p>
</form>
</body>
</html>
不用母板页可以使用,但是放在母板页里面就无效,求大大解决
<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">
</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"
BorderStyle="Dotted" Columns="55" ForeColor="#6600FF" MaxLength="200" Rows="6"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
<asp:CheckBox Text="全选/反选" runat="server" ID="cbHead" onclick="javascript:selectAll('GridView1',this.checked);">
</asp:CheckBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="phone" HeaderText="123" SortExpression="phone" />
</Columns>
</asp:GridView>
</td>
<td>
</td>
</tr>
</table>
<p>
<asp:Button ID="Button4" runat="server" Text="Button"
onclick="Button4_Click" />
</p>
</form>
</body>
</html>
不用母板页可以使用,但是放在母板页里面就无效,求大大解决
查看源文件
看看chexkbox的id是什么
用这个id试试