【发布时间】:2018-06-04 12:14:52
【问题描述】:
我有一个GridView,我必须从CheckBox 中检索检查的值,就像在GridView(按行)中,该行设置为真或假,然后我已经使用jQuery 从GridView 获取真/假等值,并将其设置为GridView 之外的另一个复选框。所以我尝试使用以下内容:
$("#grdDetails tr").click(function () {
$(this).find('td').each(function (e) {
$("#ContentPlaceHolder1_txtUserName").val($(this).closest('tr').find("span[id*=lblName]").text());
$("#ContentPlaceHolder1_txtEmail").val($(this).closest('tr').find("span[id*=lblEmail]").text());
if ($(this).closest('tr').find("input[id*=chkStatus]").attr('checked') == true) //Here I am trying to check the status of the CheckBox from GridView
{
$('#ContentPlaceHolder1_chkStatus').attr('checked', true);
}
else
{
$('#ContentPlaceHolder1_chkStatus').attr('checked', false);
}
});
});
我不确定我是否做对了并尝试从GridView 检查CheckBox 的状态。
注意:我再次写信 - GridView 有一个 Status 列,它显示是否有人或成员在网站上使用 CheckBox 处于活动状态.我的要求是当我单击一行时,应该从该特定行检索所有信息以及CheckBox 状态,如真/假。现在,我可以使用jQuery 检索除CheckBox 之外的其他值。例如,请参见下图:在第二行中,CheckBox 未选中,这意味着错误。在表单中,它也应该保持未选中状态。
【问题讨论】:
-
你可以在这里查看示例@Asif Ali。
-
试试
.is(':checked')而不是.attr('checked') -
它工作了@Alex Kudryashev - 非常感谢。您可以将其发布为答案,因此我可以标记为答案。如果你能帮忙,我有一个简单的问题。