简体   繁体   English

当数据来自数据库时,如何检查html表中的CheckBox? 在asp.net MVC中

[英]How to Check CheckBox in html table when data is coming from Database? in asp.net MVC

I am fetching Data from Database on Page load through ajax, I want to check the CheckBox when OptFlag is M. 我正在通过ajax从页面加载的数据库中获取数据,我想在OptFlag为M时检查CheckBox。

$("#tblDelChkList tbody").append('<tr id="DelChkListRow1' + (rowCount++) + '" data-tr-count="' + (dataCount++) + '">' +
         '<td>' + SNo++ + '</td>' +
         '<td> <label id="lblDelChkListCode">' + item.DelChkListCode.trim() + ' </label></td>' +
         '<td> <label id="lblDelChkListDesc">' + item.DelChkListDesc.trim() + ' </label>' +
         '<input type="text" style="display:none;" class="form-control" id="txtDocTypeDesctbl"></td>' +
         'if('+item.OptFlag+' == "M"){'+
         '<td style="text-align:center;">' +         
         '<input type="checkbox" id="chkOptFlag" class="chkBank icheckbox_minimal-blue" checked="true" >'+
         '<input type="hidden" id="hdnDocCode" value="' + item.DelChkListCode.trim() + '"/>' +
         '</td>'+
          '}else{'+
          '<td style="text-align:center;">' +         
          '<input type="checkbox" id="chkOptFlag" class="chkBank icheckbox_minimal-blue" >'+
          '<input type="hidden" id="hdnDocCode" value="' + item.DelChkListCode.trim() + '"/>' +
          '</td>}' +
          '</tr>');
      });

This is what I am getting 这就是我得到的

在此处输入图片说明

you need to do something like 你需要做类似的事情

Jquery End in index.js jQuery以index.js结尾

let users=[
    {name:'John',isMarried:true},
    {name:'Uzair',isMarried:false},
    {name:'John',isMarried:true},
        {name:'Ab',isMarried:false}
]

$(function(){

    let str='';
    users.forEach(element => {
        str+="<tr>";
        str+="<td>";
        str+=element.name;
        str+="</td>"
        str+="<td>";
        if(element.isMarried){
            str+="<input type='checkbox' id='chkOptFlag' class='chkBank icheckbox_minimal-blue' checked='true'>";
        }else{
            str+="<input type='checkbox' id='chkOptFlag' class='chkBank icheckbox_minimal-blue'>";
        }
        str+="</td>";
        str+="</tr>";
    });

    $("#tblDelChkList").append(str)
})

HTML end HTML结尾

<body>
    <table>
        <thead>
            <tr>
                <td>Name</td>
                <td>Is Married?</td>
            </tr>
        </thead>
        <tbody id="tblDelChkList">

        </tbody>
    </table>

</body>
<script src="index.js"></script>

Result 结果

查看详情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在 Asp.net MVC 中使用复选框从数据库中获取 select 数据? - How can i select data from a Database with checkbox in Asp.net MVC? 如何通过从 ASP.NET MVC 中的数据库检索数据来选中/取消选中复选框列表 - How to Check/Unchecked the check box list by retrieving the data from database in ASP.NET MVC 如何使用 MVC asp.net 从数据库中检查以逗号分隔的 model 中存在的复选框(如下面的代码所示)? - How can I check checkbox which is exists in model sepereted by coma from database (as shown below in code) using MVC asp.net? 如何在asp.net中通过JavaScript动态选中/取消选中html复选框 - How to dynamically check/uncheck html checkbox by JavaScript in asp.net 从HTML表ASP.net MVC获取使用jQuery添加的数据 - Get data added with jQuery from HTML table ASP.net MVC 如何在asp.net mvc中获取html表值? - How to get the html table value in asp.net mvc? 如何通过更改asp.net mvc下拉列表中的选项来过滤html表中的数据? - How to filter data in html table by changing option in drop down in asp.net mvc? 带有 Ajax 按钮的 Asp.net MVC 从数据库中检索数据 - Asp.net MVC with Ajax button to retrieve data from database 将jQuery数据表与ASP.NET MVC一起使用时如何更新模型数据 - How to update model data when using jQuery Data table with ASP.NET MVC asp.net mvc复选框取消选中toher - asp.net mvc checkbox uncheck on check of toher
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM