Solved

Simple checkBox question

Posted on 2004-04-28
2
229 Views
Last Modified: 2010-04-15
I have the following checkBox I am trying to display on my form but it show unchecked even though the data shows checked.

checkBox1.Text=datareader["Active"].ToString();

Any idea hoew to get it to properly display?

Jim
0
Comment
Question by:Jimbo456
2 Comments
 
LVL 21

Accepted Solution

by:
tovvenki earned 250 total points
ID: 10945852
Hi,
If the datareader["Active"] is a bit or boolean then assign it straight to the Checked property of the checkbox and not to the text property.
 or if the datareader returns a string like Checked then
checkBox1.Text=datareader["Active"].ToString();
if (checkBox1.Text == "Checked")
      checkBox1.Checked = true;
else
      checkBox1.Checked = false;


Regards,
Venki
0
 
LVL 1

Expert Comment

by:warmach
ID: 10948564
You should not be setting the Text property at all.  This property is used as a label to the check box.  Link Venki said, you need to set the Checked property directly.  I would set the Text property to something more descriptive because it is something that the user will see.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Linq help 1 16
asp.net bundle 8 36
C# code editing and collaboration 3 44
Iterate a dictionnary to change values 4 28
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now