使用datalist中的一个复选框选中所有复选框

时间:2014-06-19 08:24:35

标签: asp.net checkbox datalist

这是我的代码,当我点击复选框chkall时,应激活所有复选框。 所以请任何人帮助我

<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>
                    <asp:TextBox ID="txtename" runat="server" Width="60"></asp:TextBox>
                    <asp:TextBox ID="txtdesg" runat="server" Width="60"></asp:TextBox>
                    <asp:TextBox ID="txtdoj" runat="server" Width="60"></asp:TextBox>
                    <asp:TextBox ID="txtsalary" runat="server" Width="60"></asp:TextBox>
                    <asp:TextBox ID="txtdeptno" runat="server" Width="60"></asp:TextBox>
                    <asp:Button ID="btnadd" runat="server" Text="add" CommandArgument="add" />
                </FooterTemplate>

                <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />

            </asp:DataList>

1 个答案:

答案 0 :(得分:1)

我建议在客户端进行。以下是jquery

的示例
function checkAll(){
    $("#DataList1 :checkbox").prop("checked", $("#chkall").prop("checked"));
}