473,410 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

CheckBox.checked return a value

All,

Have a problem i just cant find the answer for.
I'm trying to populate a colum in a SQL database. Basically the
column requires a 1 or 0.
I'm trying to populate this col via a c# checkbox.

so basically:
checkbox.checked =1
else
=0

any ideas how to get this working? ive set the variable as a decimal
(is that correct?)

Thanks
Jan 31 '08 #1
3 7416
Hi,
so basically:
checkbox.checked =1
else
=0

any ideas how to get this working? ive set the variable as a decimal
(is that correct?)
Hope this is an answer to your question, try this:

int valueInSql = 1;
checkbox.Checked = (valueInSql == 1 ? true : false)

or even simply

checkbox.Checked = (valueInSql == 1);

Note that this doesn't alarm you if the value in sql was anything
other than 0 or 1.

PS. As in the example, I'd use an int for this instead of decimal, or
at least any other whole-number type, one that is large enough to hold
the type of the column in your DB.

Regards,
Jeroen
Jan 31 '08 #2
On 31 Jan, 10:36, Jeroen <mercu...@gmail.comwrote:
Hi,
so basically:
checkbox.checked =1
else
=0
any ideas how to get this working? ive set the variable as a decimal
(is that correct?)

Hope this is an answer to your question, try this:

int valueInSql = 1;
checkbox.Checked = (valueInSql == 1 ? true : false)

or even simply

checkbox.Checked = (valueInSql == 1);

Note that this doesn't alarm you if the value in sql was anything
other than 0 or 1.

PS. As in the example, I'd use an int for this instead of decimal, or
at least any other whole-number type, one that is large enough to hold
the type of the column in your DB.

Regards,
Jeroen
Thanks you mate, works a treat!
Jan 31 '08 #3
If you are binding the column to some other object which is typed as an
integer, then you might want to attach to the Format and Parse methods on
the Binding to transform the value between the data source and the bound
control. This will let you convert from an integer to a boolean and vice
versa.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"nologo" <ze****@hotmail.comwrote in message
news:ed**********************************@i72g2000 hsd.googlegroups.com...
All,

Have a problem i just cant find the answer for.
I'm trying to populate a colum in a SQL database. Basically the
column requires a 1 or 0.
I'm trying to populate this col via a c# checkbox.

so basically:
checkbox.checked =1
else
=0

any ideas how to get this working? ive set the variable as a decimal
(is that correct?)

Thanks
Jan 31 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Champagne | last post by:
We have an application to where you can select/deselect all checkboxes in a checkbox array by clicking a 'master' checkbox at the top of the screen. This seems to work fine unless there is only...
4
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button...
6
by: Dennis Allen | last post by:
Hi. I got a checkbox in a form. When the form is submitted, an email is generated. In the email text is the field name: on or off. The client doesn't want to see on or off, but yes or no. ...
0
by: Zürcher See | last post by:
I have a checkbox as sample, I have to create n-checkbox like that one in a webform, so I have extended the CheckBox class and wrote a public clone method that use the protected MemberwiseClone...
6
by: Alessandro Rossi | last post by:
Hi, I have to create a CheckBox, and i would like will be checked if there is a value in a property added, and not checked if there is another value. I added 2 property (string) to the checkbox;...
1
by: dx | last post by:
I'm extremely frustrated with ASP.NET...again! To me this should be as simple as setting oCheckBox.Checked = True.. yet for some reason it isn't. I have a user control (ascx) that that has a...
34
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
3
by: uremog | last post by:
I have a set of of check boxes. onClick, the checkboxes call check_radio and recup_checkbox. the referenced radios function as group selectors. check_radio just unchecks the radios if someone...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.