aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="wangyibushuaxinyemian.aspx.cs" Inherits="_12._18zuoye.wangyibushuaxinyemian" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server"> <title></title> <script language="javascript" type="text/javascript">// <![CDATA[function change(sender) {
var table = document.getElementById("GridView1");
for (var i = 1; i < table.rows.length; i++) { table.rows[i].cells[0].getElementsByTagName("input")[0].checked = sender.checked;}
}
// ]]>
</script></head><body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="sid" DataSourceID="SqlDataSource1"> <Columns> <asp:TemplateField> <HeaderTemplate> <input id="Checkbox2" type="checkbox" οnclick="return change(this)" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="sid" HeaderText="sid" InsertVisible="False" ReadOnly="True" SortExpression="sid" /> <asp:BoundField DataField="sname" HeaderText="sname" SortExpression="sname" /> <asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" /> <asp:BoundField DataField="age" HeaderText="age" SortExpression="age" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:studentConnectionString %>" DeleteCommand="DELETE FROM [student] WHERE [sid] = @sid" InsertCommand="INSERT INTO [student] ([sname], [sex], [age]) VALUES (@sname, @sex, @age)" SelectCommand="SELECT [sid], [sname], [sex], [age] FROM [student]" UpdateCommand="UPDATE [student] SET [sname] = @sname, [sex] = @sex, [age] = @age WHERE [sid] = @sid"> <DeleteParameters> <asp:Parameter Name="sid" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="sname" Type="String" /> <asp:Parameter Name="sex" Type="String" /> <asp:Parameter Name="age" Type="Byte" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="sname" Type="String" /> <asp:Parameter Name="sex" Type="String" /> <asp:Parameter Name="age" Type="Byte" /> <asp:Parameter Name="sid" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource> </div> </form></body></html>aspx文件样式:
Web.config文件:
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细消息,请访问 --><configuration>
<connectionStrings> <add name="studentConnectionString" connectionString="Data Source=PC;Initial Catalog=student;User ID=sa;Password=linlin" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web></configuration>