Check if checkbox is checked or not (ASPX)
- by cthulhu
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).