Check if checkbox is checked or not (ASPX)

Posted by cthulhu on Stack Overflow See other posts from Stack Overflow or by cthulhu
Published on 2010-05-25T14:58:24Z Indexed on 2010/05/25 15:01 UTC
Read the original article Hit count: 249

Filed under:
|
|

I have the following code:

(some.aspx.cs)

        if(Page.IsPostBack)
        {
        bool apple2 = false;
        bool pizza2 = false;
        bool orange2 = false;
        if (apple.Checked)
            apple2 = true;
        if (pizza.Checked)
            pizza2 = true;
        if (orange.Checked)
            orange2 = true;
        }

(some.aspx)

 <tr>
 <td>Food:</td>
 <td>Apple <input type="checkbox" name="food" id="apple" value="apple" runat="server" />Pizza <input type="checkbox" name="food" id="pizza" value="pizza" runat="server" />Orange <input type="checkbox" name="food" id="orange" value="orange" runat="server" /></td>

Now, i send the Boolean variables to SQL database. The problem is only with unchecked boxes. I mean, when you check some checkboxes it sends it as true (and that's right) but when i uncheck them it remains the same (true).

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql-server