How to check a checkbox with jQuery

To check a checkbox with jQuery you can use the snippet below.

Sample jQuery 1.6+

$('.Checkbox').prop('checked', true); //change true to false to set checked state to false

Sample jQuery 1.5 and below

$('.Checkbox').attr('checked', true);  //change true to false to set checked state to false

Please rate this snippet

How to change Checkstate of an item in a checkedlistbox control in C# or VB.NET

To change the Checkstate of an item in a checkedlistbox control in C# or VB.NET you can use the SetItemCheckState method of the checkedlistbox control.

Sample C#

private void ChangeCheckStateForAllCheckBoxes(bool check) {
    for (int i = 0; i <= (checkedListBox1.Items.Count - 1); i++) {
        if (check)
        {
            checkedListBox1.SetItemCheckState(i, CheckState.Checked);
        }
        else
        {
            checkedListBox1.SetItemCheckState(i, CheckState.Unchecked);
        }
    }  
}

Sample VB.NET

Private Sub ChangeCheckStateForAllCheckBoxes(check As Boolean)
	For i As Integer = 0 To (checkedListBox1.Items.Count - 1)
		If check Then
			checkedListBox1.SetItemCheckState(i, CheckState.Checked)
		Else
			checkedListBox1.SetItemCheckState(i, CheckState.Unchecked)
		End If
	Next
End Sub

for more informations see CheckedListBox.ObjectCollection Class, CheckedListBox.SetItemChecked Method

Please rate this snippet