0

I have a form with a check box list in it. The check box list is databound to a table in the database. I need to set a default value for the check box when the pages loads and when I click a clear button to clear all the text boxes etc, that are on the form. Can someone tell me how to o that?

1 Answer 1

1

//Check particular checkbox

    foreach (ListItem item in CheckBoxList1.Items)
    {
        if (item.Text.Trim() == "C#")//text or value (item.Value.Trim())
        {
            item.Selected = true;
        }
    }

    //check all checkbox
    foreach (ListItem li in CheckBoxList1.Items)
    {
        li.Selected = true;
    } 

//uncheck

protected void Button1_Click(object sender, EventArgs e)
{
    foreach(ListItem li in CheckBoxList1.Items)
    {
        li.Selected = false;
    } 
}

Using jQuery clear all the inputs of form

<script type="text/javascript">
    $("#Button1").click(function() {
        $('#form1').find(':input').each(function() {
            switch (this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
            }
        });
    });
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.