关闭

利用javascript实现复选框的全选功能

103人阅读 评论(0) 收藏 举报

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm43.aspx.cs" Inherits="ASP.NETWebControlDaQuan.WebForm43" %>

<!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">
        //利用javascript实现复选框的全选功能
        function allSelect() {
            var v1 = document.getElementById("selectAll");
            var v2 = document.getElementsByName("select");
            for (var i = 0; i < v2.length; i++) {
                v2[i].checked = v1.checked;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:GridView ID="gv" runat="server" DataSourceID="studentDataSource" AllowPaging="true">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <input type="checkbox" id="selectAll" onclick="allSelect()" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <input type="checkbox" name="select" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="studentDataSource" runat="server" ConnectionString="server=(local);database=db_students;integrated security=true" SelectCommand="select top 100 * from CwwTest">
            </asp:SqlDataSource>
        </div>
    </form>
</body>
</html>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3916次
    • 积分:141
    • 等级:
    • 排名:千里之外
    • 原创:13篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档