【问题标题】:Get Checked True/False From GridView in jQuery在 jQuery 中从 GridView 中检查真/假
【发布时间】:2018-06-04 12:14:52
【问题描述】:

我有一个GridView,我必须从CheckBox 中检索检查的值,就像在GridView(按行)中,该行设置为真或假,然后我已经使用jQueryGridView 获取真/假等值,并将其设置为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 - 非常感谢。您可以将其发布为答案,因此我可以标记为答案。如果你能帮忙,我有一个简单的问题。

标签: jquery asp.net gridview


【解决方案1】:

jQuery .attr 工作正常当属性被硬编码时。对于客户端更改的属性/状态,还有其他方法。我会像这样重写代码。

 if ($(this).closest('tr').find("input[id*=chkStatus]").is(':checked')/* redundant == true*/)
 {
       $('#ContentPlaceHolder1_chkStatus').prop('checked', true);
 }
 else
 {
       $('#ContentPlaceHolder1_chkStatus').prop('checked', false);
 }

【讨论】:

    猜你喜欢
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    相关资源
    最近更新 更多