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>
</tr>
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).
Addition:
Why too little?
here’s a query…nothing special here
string q = string.Format(@"UPDATE tblUsers SET ......., apple='{8}', orange='{9}' WHERE id='{10}'", ...., apple2, orange2, id);
lib.sql_query(q); // using my sql library...
the datatype is bit….i tried also with string…but no success
P.S. – i also tried with Request.Form[“apple”], and the uncheck worked…but unfortunately the check didn’t…when i check the checkbox it throws me an error:
Conversion failed when converting the varchar value 'on' to data type bit.
Somebody?
So after a long time of combinations and other stuff it worked…Without any javascripts and hidden fields…
that’s the .cs code