I am using javascript to make unchecked GridView .
But whenever I try, I cannot make unchecked it.
function UncheckedItemsCheckBox(CheckboxID) {
var checkbox = document.getElementById(CheckboxID);
checkbox.checked = false;
alert(checkbox.id + " : " + checkbox.name + " : " + checkbox.checked);
}
Here is the output.
---------------------------
Message from webpage
---------------------------
GridView1_ctl02_txtDoseQty : GridView1$ctl02$txtDoseQty : false
---------------------------
OK
---------------------------
Even though “checkbox.checked” return me “false” as output message shown, but at the gridview checkbox is still checked.
Could anyone please give me suggestion?
What may be happening is that your
CheckBoxIDis wrong, and therefore returning the wrong element.In JavaScript, saying
checkbox.checked = false;will, if this object did not previously have acheckedproperty, add one to the object, with the value provided. So, if yourCheckBoxIDis in fact wrong, it’s no surprise your alert shows false; any non-null element you pull back withgetElementByIdwill allow you to add a checked property to it.More specifically, in
asp.netwhen you create a checkbox column, like thisit renders html like this:
A couple possibilities:
You’re setting the checkbox to be checked, but since it’s disabled, it’s not updating its state— ok, it looks like disabled checkboxes can have their checked properties updated. Hopefully #1 is your problem.A good place to start debugging would be to change your function to this