• CheckBox全选与不全选(不用刷新页面)


    aspx文件:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="wangyibushuaxinyemian.aspx.cs" Inherits="_12._18zuoye.wangyibushuaxinyemian" %>

    <!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>
        <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" onclick="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 应用程序的详细消息,请访问
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->

    <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>

  • 相关阅读:
    年轻人的第一个 Spring Boot 应用,太爽了!
    面试问我 Java 逃逸分析,瞬间被秒杀了。。
    Spring Boot 配置文件 bootstrap vs application 到底有什么区别?
    坑爹的 Java 可变参数,把我整得够惨。。
    6月来了,Java还是第一!
    Eclipse 最常用的 10 组快捷键,个个牛逼!
    Spring Cloud Eureka 自我保护机制实战分析
    今天是 Java 诞生日,Java 24 岁了!
    厉害了,Dubbo 正式毕业!
    Spring Boot 2.1.5 正式发布,1.5.x 即将结束使命!
  • 原文地址:https://www.cnblogs.com/duanlinlin/p/2825926.html
Copyright © 2020-2023  润新知