[英]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.