473,395 Members | 1,885 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,395 software developers and data experts.

Databinding Checkboxes

My form has multiple checkboxes. The user can select any number of these
checkboxes (including none). I have a table in my DB that would have one
entry per checkbox if the checkbox has been checked. If it hasn't been
checked, then the table will not have an entry.

What is the best way to bind my checkboxes to that table (which is loaded
into a dataset)?

Thanks much!
Mike
Nov 21 '05 #1
13 1616
You can bind the "Checked" property of each checkbox to the
corresponding datacolumn in the Datatable of your Dataset.

Nov 21 '05 #2
Oops, sorry, I misread your post. did you mean to say that for each
checkbox that is Checked, a row will be added to your database table?

Nov 21 '05 #3
You cant do that with the standard databinding. All controls will be bound
to the single current record. You can use a grid, perhaps, but it will
still be difficult.
"Mike" <pc**********@bellsouth.net> wrote in message
news:J2**********@bignews3.bellsouth.net...
My form has multiple checkboxes. The user can select any number of these
checkboxes (including none). I have a table in my DB that would have one
entry per checkbox if the checkbox has been checked. If it hasn't been
checked, then the table will not have an entry.

What is the best way to bind my checkboxes to that table (which is loaded
into a dataset)?

Thanks much!
Mike

Nov 21 '05 #4
Yes, that is what I said.

The simple binding (one for one) is straightforward. My question is how do I
bind the checkbox to data that is not there?

"Jerry H." <bo*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Oops, sorry, I misread your post. did you mean to say that for each
checkbox that is Checked, a row will be added to your database table?

Nov 21 '05 #5
Let me add some clarification.

I'm not storing a boolean value in the database. The user checking the
checkbox causes my code to create an entry in the table. The presence of
this entry will drive the "checked" value the next time it is shown. In
other words, if no entry exits, then the checkbox is not checked. If an
entry exists, then the checkbox is checked.

I'm thinking this may come down to me creating a new column for my table in
the dataset and binding that column to the checked value. I would also need
to add any missing rows. I definitely do not like this approach, although it
could be done.

Thanks very much for your help.
"Mike" <pc**********@bellsouth.net> wrote in message
news:rw***********@bignews3.bellsouth.net...
Yes, that is what I said.

The simple binding (one for one) is straightforward. My question is how do
I bind the checkbox to data that is not there?

"Jerry H." <bo*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Oops, sorry, I misread your post. did you mean to say that for each
checkbox that is Checked, a row will be added to your database table?


Nov 21 '05 #6
Jerry,

What is wrong, I do it in that way?

:-)

Cor
Nov 21 '05 #7
Cor,

I'm all ears (and eyes). Please expand my knowledgebase - I would greatly
appreciate it!

Thanks!
Mike

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Jerry,

What is wrong, I do it in that way?

:-)

Cor

Nov 21 '05 #8
Mike,

You can not bind to nothing.

Therefore as you want it to do your way, than it is just old checking.

If mydatarow Is Nothing then
mycheckbox.checked = true
end if

And using the checkstate change event to create newrows.

Although this is in my opinion a strange and probably quick to spaghetti and
errors leading solution. (You have by instance to protect by disabling that
checkbox (what looks weird) the use of that checkbox again.

However just my thought,

Cor
Nov 21 '05 #9
Cor,

We agree - I do not prefer to handle it this way. I just don't know enough
to do it a better way. I'm thinking you might, though. :)

Can you offer me some suggestions?

Thanks!
Mike

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:u%***************@TK2MSFTNGP10.phx.gbl...
Mike,

You can not bind to nothing.

Therefore as you want it to do your way, than it is just old checking.

If mydatarow Is Nothing then
mycheckbox.checked = true
end if

And using the checkstate change event to create newrows.

Although this is in my opinion a strange and probably quick to spaghetti
and errors leading solution. (You have by instance to protect by disabling
that checkbox (what looks weird) the use of that checkbox again.

However just my thought,

Cor

Nov 21 '05 #10
Mike,

What if your user unchecks the checkbox, what is than the action?

Cor
"Mike" <pc**********@bellsouth.net> schreef in bericht
news:nQ************@bignews3.bellsouth.net...
Cor,

We agree - I do not prefer to handle it this way. I just don't know enough
to do it a better way. I'm thinking you might, though. :)

Can you offer me some suggestions?

Thanks!
Mike

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:u%***************@TK2MSFTNGP10.phx.gbl...
Mike,

You can not bind to nothing.

Therefore as you want it to do your way, than it is just old checking.

If mydatarow Is Nothing then
mycheckbox.checked = true
end if

And using the checkstate change event to create newrows.

Although this is in my opinion a strange and probably quick to spaghetti
and errors leading solution. (You have by instance to protect by
disabling that checkbox (what looks weird) the use of that checkbox
again.

However just my thought,

Cor


Nov 21 '05 #11
Cor,

I'll try to give you more detail to help you understand what I am doing.

I'm trying to track records for a kid's club I'm involved with. Each child
works through books. The books have awards. Each award consists of a
variable number of sections.

Among other things (datepicker, combo box with names of children, etc.), the
form has the following:

<label with award name> <chkbox> <chkbox> <chkbox> ... [as many as
necessary for this award]
Nov 21 '05 #12
Mike,

I took some time to make a sample for you in the way I would probably do it.
It are the basics not all things you ask have I implemented.

http://www.vb-tips.com/default.aspx?...4-d5f9861ba534

I hope this helps,

Cor
Nov 21 '05 #13
Thank you, Cor, for taking your time to help. I will review your sample
later today and let you know if it does what I need.

Thanks again!
Mike

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uy**************@TK2MSFTNGP10.phx.gbl...
Mike,

I took some time to make a sample for you in the way I would probably do
it. It are the basics not all things you ask have I implemented.

http://www.vb-tips.com/default.aspx?...4-d5f9861ba534

I hope this helps,

Cor

Nov 21 '05 #14

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

Similar topics

2
by: sdeezdaone | last post by:
I've got two tables that are linked by a field. The first table contains a list of items (like a checklist). The second table contains the corresponding a record for each user and each checklist...
0
by: dan.benge | last post by:
I have a form with some text boxes, checkboxes and DateTimePicker controls. I've bound these controls to fields in a dataview. The problem is when I set the filter on the dataview the controls are...
3
by: Steven C | last post by:
Hi, can any one help with this frustrating problem. I have a dataset filled from a Jet database via a paramaterised query. I dynamically bind each control to a dataview each time a next /...
1
by: Simon | last post by:
Guys, I have a webpage with DropDownLists, TexbBoxes, CheckBoxes and Labels all databound to a DataSet. When I first load the page, Databinding happens as expected. However, if I PostBack,...
0
by: vbMental | last post by:
I created a user control that, had a datalist with checkboxes inside of the item template. These checkboxes would not retain state. For instance, if I set them to checked inside of the load event...
3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
0
by: Dwight | last post by:
The project I'm working on is using data classes to pass the data between layers. In one from I databind the class data to checkboxes. ..chbCslty_Loss_Ind.DataBindings.Add("checked",...
0
by: Andy B | last post by:
I have a CheckBoxList that I want to dataBind to an XElement. I got this far: CheckBoxLisgt.DataSource = StockContract.Element("Glossary").Elements("Term"); CheckBoxList.DataBind(); It works...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.