如何使用Java脚本代码使用一个复选框选择所有复选框 [英] How Do I Select All Checkboxes Using One Checkbox Using Java Script Code
本文介绍了如何使用Java脚本代码使用一个复选框选择所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<%@ Page 语言 = C# AutoEventWireup = true CodeFile = Default7.aspx.cs 继承 = Default7 %>
< !DOCTYPE html >
< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = 服务器 >
< title > < / title >
< 脚本 type = text / javascript >
function checktrue()
{
var x = document .getElementById(' <%= DataList1.ClientID%>');
}
< / script >
< / head >
< ; 正文 >
< 表格 id = form1 runat = server >
< div >
< asp:DataList ID = DataList1 runat < span class =code-keyword> = server OnItemCommand = DataList1_ItemCommand CellPadding = 4 ForeColor = #333333 >
< 页脚 样式 backcolor = #507CD1 font-bold = True forecolor = 白色 / >
< < span class =code-leadattribute> HeaderStyle BackColor = #507CD1 Font-Bold = < span class =code-keyword> True ForeColor = 白色 / >
< HeaderTemplate >
< asp:CheckBox ID = chkall runat < span class =code-keyword> = server onclick = checktrue() / >
EMPID ENAME DESIGNATION DOJ SALARY DEPTNO编辑/更新
< / HeaderTemplate >
< item style backcolor = #EFF3FB / >
< itemtemplate >
< asp:CheckBox ID = chkone runat = server / >
< asp:标签 ID = lblempid runat = 服务器 文本 =' <% #Eval( empid)%> ' / >
<% #Eval( ename)%>
<% #Eval( desg)%>
<% #Eval( doj)%>
<% #Eval( salary)%>
<% #Eval( deptno)%>
< ; asp:按钮 ID = btnedit runat = server 文本 = 编辑 CommandName = 编辑 / >
< / itemtemplate >
< ; alternatingitem style < span class =code-attribute> backcolor = 白色 / >
< edititemtemplate >
< asp:标签 ID = lblempid runat = server 文本 =' < % #Eval( empid) %> ' / >
< asp:TextBox ID = txtename runat = server 文字 =' <% #Eval( ename)% > ' / >
< asp:TextBox ID = txtdesg runat = 服务器 正文 =' <% #Eval( desg)%> ' / >
< asp:TextBox ID = txtdoj runat = server 文字 =' <% #Eval( doj)%> ' / >
< asp:TextBox ID = txtsalary runat = server < span class =code-attribute> 文字 =' <% #Eval( salary)%> ' / >
< asp:TextBox ID = txtdeptno runat = server 文本 =' <% #Eval( d eptno)%> ' / >
< asp:按钮 ID = btnupdate runat = server 文本 = 更新 CommandName = 更新 / >
< asp:按钮 ID = btncancel runat = server 文本 = 取消 CommandName = 取消 / >
< / edititemtemplate >
< footertemplate < span class =code-keyword>>
< asp:Button ID = btmdelete runat = server OnClick = btndelete_Click < span class =code-attribute>文本 = 删除 / < span class =code-keyword>>
< asp :TextBox ID = txtempid runat = server 宽度 = 60 > ;
< asp:TextBox ID = txtename runat = server 宽度 = 60 >
< asp:TextBox ID = txtdesg runat = server 宽度 < span class =code-keyword> = 60 >
< asp:TextBox ID = txtdoj runat = server 宽度 = 60 >
< asp:TextBox < span class =code-attribute> ID = txtsalary runat = server 宽度 = 60 >
< asp:TextBox ID = txtdeptno runat = 服务器 宽度 = 60 >
< asp:按钮 ID = btnadd runat = 服务器 文本 = 添加 CommandArgument = 添加 / >
< / footertemplate >
< < span class =code-leadattribute> SelectedItemStyle BackColor = #D1DDF1 Font-Bold = True ForeColor = #333333 / >
< br / >
< / div >
< / form >
< / body >
< / html >
解决方案
请检查以下链接:
选择/取消选择GridView内的所有CheckBox [ ^ ]
如何在asp.net中检查标题模板时检查gridview中的所有复选框 [ ^ ]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function checktrue()
{
var x = document.getElementById('<%=DataList1.ClientID%>');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" OnItemCommand="DataList1_ItemCommand" CellPadding="4" ForeColor="#333333">
<footerstyle backcolor="#507CD1" font-bold="True" forecolor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderTemplate>
<asp:CheckBox ID="chkall" runat="server" onclick="checktrue()" />
EMPID ENAME DESIGNATION DOJ SALARY DEPTNO Edit/Update
</HeaderTemplate>
<itemstyle backcolor="#EFF3FB" />
<itemtemplate>
<asp:CheckBox ID="chkone" runat="server" />
<asp:Label ID="lblempid" runat="server" Text='<%#Eval("empid") %>' />
<%#Eval("ename") %>
<%#Eval("desg") %>
<%#Eval("doj") %>
<%#Eval("salary") %>
<%#Eval("deptno") %>
<asp:Button ID="btnedit" runat="server" Text="EDIT" CommandName="Edit" />
</itemtemplate>
<alternatingitemstyle backcolor="White" />
<edititemtemplate>
<asp:Label ID="lblempid" runat="server" Text='<%#Eval("empid") %>' />
<asp:TextBox ID="txtename" runat="server" Text='<%#Eval("ename") %>' />
<asp:TextBox ID="txtdesg" runat="server" Text='<%#Eval("desg") %>' />
<asp:TextBox ID="txtdoj" runat="server" Text='<%#Eval("doj") %>' />
<asp:TextBox ID="txtsalary" runat="server" Text='<%#Eval("salary") %>' />
<asp:TextBox ID="txtdeptno" runat="server" Text='<%#Eval("deptno") %>' />
<asp:Button ID="btnupdate" runat="server" Text="Update" CommandName="Update" />
<asp:Button ID="btncancel" runat="server" Text="Cancel" CommandName="Cancel" />
</edititemtemplate>
<footertemplate>
<asp:Button ID="btmdelete" runat="server" OnClick="btndelete_Click" Text="Delete" />
<asp:TextBox ID="txtempid" runat="server" Width="60">
<asp:TextBox ID="txtename" runat="server" Width="60">
<asp:TextBox ID="txtdesg" runat="server" Width="60">
<asp:TextBox ID="txtdoj" runat="server" Width="60">
<asp:TextBox ID="txtsalary" runat="server" Width="60">
<asp:TextBox ID="txtdeptno" runat="server" Width="60">
<asp:Button ID="btnadd" runat="server" Text="add" CommandArgument="add" />
</footertemplate>
<SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<br />
</div>
</form>
</body>
</html>
解决方案
Please check following links :
Selecting / Deselecting all the CheckBoxes Inside a GridView[^]
how to check all checkboxes in gridview when checked header template in asp.net[^]
这篇关于如何使用Java脚本代码使用一个复选框选择所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文