在jQuery中单击asp:linkbutton时,选中GridView中的所有复选框

时间:2014-03-19 20:27:28

标签: jquery asp.net

我想使用asp:linkbutton选择gridview中的所有复选框。以下是我对此行所不能确定的内容 - $(this("id*='chkGrid']").attr('checked', true));

$('.SelectAll').click(SelectAll);

function SelectAll() {
    $('#gvw tr').each(function () {
        $(this("id*='chkGrid']").attr('checked', true));
    });
}

而且:

<asp:GridView ID="gvw" BorderColor="black" RowStyle-BorderColor="LightGray" BorderWidth="1" runat="server" HorizontalAlign="Left" HeaderStyle-CssClass="headerStyle"
     HeaderStyle-BackColor="LightGray" OnRowCommand="gvw_RowCommand" Height="35px" AllowSorting="true" OnSorting="gvw_Sorting"
     GridLines="Both" DataKeyNames="TicketID" Width="98%" AutoGenerateColumns="false" EmptyDataText="No data found." CellPadding="2" >
    <Columns>
        <asp:TemplateField ItemStyle-BackColor="LightBlue" HeaderStyle-Font-Bold="false">
            <ItemTemplate>&nbsp;&nbsp;</ItemTemplate>
        </asp:TemplateField>

                                          

    </Columns> 
</asp:GridView>

<asp:LinkButton ID="lnkSelectAll" runat="server" CssClass="SelectAll" OnClientClick="SelectAll();" >Select All</asp:LinkButton>

1 个答案:

答案 0 :(得分:0)

这样的东西
$('#gvw').find('input:checkbox').prop('checked', true);

从jQuery 1.6开始,您应该使用prop而不是attr设置复选框状态,因为attr已被弃用:http://api.jquery.com/prop/

相关问题