I have a checkbox(As a cloumn to check if the user is active or not) on a kendo Grid Update Window.It is always shown unchecked even though its value is 1(which means User is active).If i check when i debug the VAlue is true if the user is Active but the checkbox is not checked. Can anyone help me with the jquery syntax for this.
<td>
<div>
<label for="Active">Active</label>
</div>
<div class="checker" >
<input id="Z_ACTIVE" type="checkbox" />
</div>
</td>
HTML (When i run the code) for one field when its value is 1(Active):
<span>
<input id="Z_ACTIVE" type="checkbox" value="true">
</span>
尝试
<input id="Z_ACTIVE" type="checkbox" checked/>
Give below a try:
<div class="checker" >
<input id="Z_ACTIVE" type="checkbox"
<% if(DBValue=="1") { %>
"checked" <% } %>
/>
</div>
Since you have tagged your question with asp.net
, why aren't you using the Controls provided?
In the .aspx page
<asp:CheckBox ID="Z_ACTIVE" runat="server" />
And then in code behind
if (yourDBvalue == 1)
{
Z_ACTIVE.Checked = true;
}
you write value is 1 from the database
, but that does not magically set a random checkbox to checked if you don't tell it to.
The below Code worked for me
if (Active == "true") {
$("#Active").find('#Active input').attr('checked', 'checked');
}
else {
$("#Active").find("SPAN:first-child").removeClass("checked");
}
In the jQuery, you can have the below line.
$("#Z-ACTIVE").attr("checked", true);
Insert your condition above this line to have the database value checked.
In order to check a checkbox in HTML -
should work as mentioned in the above answers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.