zoukankan      html  css  js  c++  java
  • GridView中添加一个CheckBox列

    1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridView_CheckBoxColumn.aspx.cs" Inherits="GridSamples_GridView_CheckBoxColumn" %>
    2
    3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    4
    5<html xmlns="http://www.w3.org/1999/xhtml" >
    6<head runat="server">
    7    <title>无标题页</title>
    8    <script language="javascript" type="text/javascript">
    9    function selectAll(obj)
    10    {
    11        var theTable = obj.parentElement.parentElement.parentElement;
    12        var i;
    13        var j = obj.parentElement.cellIndex;
    14        
    15        for(i=0;i<theTable.rows.length;i++)
    16        {
    17            var objCheckBox = theTable.rows[i].cells[j].firstChild;
    18            if(objCheckBox.checked!=null)objCheckBox.checked = obj.checked;
    19        }
    20    }
    21    </script>
    22</head>
    23<body>
    24    <form id="form1" runat="server">
    25    <div>
    26        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
    27            DataKeyNames="id" DataSourceID="AccessDataSource1" AllowSorting="True" OnDataBinding="GridView1_DataBinding" OnRowDataBound="GridView1_RowDataBound">
    28            <Columns>
    29                <asp:TemplateField>
    30                    <ItemTemplate>
    31                        <asp:CheckBox ID="CheckBox1" runat="server" Checked="True" Text='<%#DataBinder.Eval(Container.DataItem,"id") %>' />
    32                    </ItemTemplate>
    33                    <HeaderTemplate>
    34                        &nbsp;<input id="CheckAll" type="checkbox" onclick="selectAll(this);" />本页全选
    35                    </HeaderTemplate>
    36                </asp:TemplateField>
    37                <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
    38                    SortExpression="id" />
    39                <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
    40                <asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" />
    41                <asp:BoundField DataField="deptid" HeaderText="deptid" SortExpression="deptid" />
    42            </Columns>
    43        </asp:GridView>
    44        &nbsp;
    45      
    46        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/test.mdb"
    47            SelectCommand="SELECT [id], [name], [sex], [deptid] FROM [employees]"></asp:AccessDataSource>
    48        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="ShowAllSelectedItem" />
    49        <asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox></div>
    50    </form>
    51</body>
    52</html>

  • 相关阅读:
    背水一战 Windows 10 (61)
    背水一战 Windows 10 (60)
    背水一战 Windows 10 (59)
    背水一战 Windows 10 (58)
    背水一战 Windows 10 (57)
    背水一战 Windows 10 (56)
    背水一战 Windows 10 (55)
    背水一战 Windows 10 (54)
    背水一战 Windows 10 (53)
    背水一战 Windows 10 (52)
  • 原文地址:https://www.cnblogs.com/nocoding/p/2666223.html
Copyright © 2011-2022 走看看