从jQuery中的GridView获取Check of True / False

问题描述 投票:1回答:1

我有一个GridView,我要从CheckBox检索已检查的值,如果在GridView(行方式),行设置为true或false,那么我将得到像true / false这样的值使用GridViewjQuery并将其设置为GridView之外的另一个CheckBox。所以我试图使用以下内容:

$("#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);
         }
    });
});

我不确定我是否正在做正确的事情,并试图从CheckBox检查GridView的状态。

注意:我正在写作 - GridView有一个列状态,它显示任何人或成员是否在网站中使用CheckBox处于活动状态。我的要求是当我点击一行时,它应该从该特定行检索所有信息,并且CheckBox状态也是如此。现在,除了jQuery之外,我能够使用CheckBox检索其他值。例如,请参见下图:在第二行中,未选中CheckBox,表示错误。在表单中,它也应该保持不受控制。

Check Status

jquery asp.net gridview
1个回答
2
投票

当属性被硬编码时,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);
 }
© www.soinside.com 2019 - 2024. All rights reserved.