473,950 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Individual CheckBox Web Controls ..HELP

I'm using three checkbox web controls in C# .NET

and one button, and one labe

Is there a way to "group" these individual checkbox web controls

If so, do I use a for loop, hashtable, array, etc

What I'm looking for is how to determine what checkbox was selected from the three checkbox web controls and have the selected checkbox(es) display in a label

I don't want to use the following

if (CheckBox1.Chec ked == true

//do something

if (CheckBox2.Chec ked == true

//do somethin

and so fort

What if I had 50 Individual Checkbox web controls I don't want to have the above if statement 50 times in my code behind

I want to have something else-such as a loop that will iterate through the Individual Checkbox controls to check which is selected and print the selected out to the label

Can this be done without using CheckBoxList web control

Any suggestions would be appreciated

Thanks

bebo

code

<asp:CheckBox id="CheckBox1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 32px" runat="server
Text="aaa"></asp:CheckBox><a sp:CheckBox id="CheckBox2" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 64px" runat="server
Text="bbb"></asp:CheckBox><a sp:CheckBox id="CheckBox3" style="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 96px" runat="server
Text="ccc"></asp:CheckBox><a sp:Button id="Button1" style="Z-INDEX: 104; LEFT: 40px; POSITION: absolute; TOP: 144px" runat="server
Text="Button"></asp:Button><asp :Label id="Label1" style="Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 48px" runat="server"> </asp:Label

******

Nov 18 '05 #1
2 2115
"=?Utf-8?B?YmVib3A=?=" <an*******@disc ussions.microso ft.com> wrote in
news:7A******** *************** ***********@mic rosoft.com:
Is there a way to "group" these individual checkbox web controls?


How about storing them in an array?

You could also loop through and find the list of checkboxes, but if you have
others you would have to separate them out.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"
ELKNews - Get your free copy at http://www.atozedsoftware.com

Nov 18 '05 #2
Create one common event handler for all 3 controls by adding the controls
and their event to the "handles" clause of the routine. Then use the
"sender" argument to determine which checkbox fired the event.

I don't have the C# code for you but here it is in VB.NET:

Public Sub SomeCheckBoxGot Clicked(sender as object, e as eventArgs) _
Handles chkBox1.checkCh anged, chkBox2.checkCh anged, chkBox3.checkCh anged

'Since you know that only a checkbox could have fired this event, it's
ok to cast sender as a checkbox
'and look at some property that uniquely identifies it, such as its ID
Select Case CType(sender, System.Web.UI.C heckbox).ID
Case "chkBox1"
do something
Case "chkBox2"
do something
Case "chkBox3"
do something
End Select
End Sub
"bebop" <an*******@disc ussions.microso ft.com> wrote in message
news:7A******** *************** ***********@mic rosoft.com...
I'm using three checkbox web controls in C# .NET

and one button, and one label

Is there a way to "group" these individual checkbox web controls?

If so, do I use a for loop, hashtable, array, etc.

What I'm looking for is how to determine what checkbox was selected from the three checkbox web controls and have the selected checkbox(es) display
in a label.
I don't want to use the following:

if (CheckBox1.Chec ked == true)
{
//do something
}
if (CheckBox2.Chec ked == true)
{
//do something
}
and so forth

What if I had 50 Individual Checkbox web controls I don't want to have the above if statement 50 times in my code behind;
I want to have something else-such as a loop that will iterate through the Individual Checkbox controls to check which is selected and print the
selected out to the label.
Can this be done without using CheckBoxList web control?

Any suggestions would be appreciated.

Thanks.

bebop

code:

<asp:CheckBox id="CheckBox1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 32px" runat="server" Text="aaa"></asp:CheckBox><a sp:CheckBox id="CheckBox2" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 64px" runat="server" Text="bbb"></asp:CheckBox><a sp:CheckBox id="CheckBox3" style="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 96px" runat="server" Text="ccc"></asp:CheckBox><a sp:Button id="Button1" style="Z-INDEX: 104; LEFT: 40px; POSITION: absolute; TOP: 144px" runat="server" Text="Button"></asp:Button><asp :Label id="Label1" style="Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 48px" runat="server"> </asp:Label>
*******

Nov 18 '05 #3

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

Similar topics

0
278
by: bebop | last post by:
I'm using three checkbox web controls in C# .NET and one button, and one labe Is there a way to "group" these individual checkbox web controls If so, do I use a for loop, hashtable, array, etc What I'm looking for is how to determine what checkbox was selected from the three checkbox web controls and have the selected checkbox(es) display in a label
6
3442
by: ML.Steve | last post by:
Hi, There are lots of posts on this subject but after a couple of hours of going though them I still can't get a number of fields to be disabled when a checkbox is ticked. Basically I have a lot of Forecast and Actual dates that can be entered, and next to each one an 'NA' checkbox that I want to disable/grey-out both dates (and the JavaScript calendar if possible). It also only has to work on Internet Explorer 6, as it is for...
3
4864
by: Randy | last post by:
Hello, I'm creating a table on the fly that is used by a datagrid. I'm also creating a tableStyle that is used for the datagrid to make it look like I want. I'm using the DataGridBoolColumn to make one column a CheckBox field. It shows up fine...as a CheckBox. I looped through the table and stored a true or false in the checkbox column but it appears to have no effect on the checkbox column. No matter what I store there (true/false), when...
0
2419
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a CheckBox Programmatically" in my code. I have changed it to use a OLDDB.DBReader to populate the datagrid and for the databinding. It works perfectly - also when using the edit-mode in the datagrid.
3
1524
by: Amy Snyder | last post by:
For what I thought would be a very simple task is turning out to be very frustrating. I have been trying for a day now to extract checkbox values from my form and nothing is working. On my form load I am setting the values of my checkboxes: chk1.Attributes.Add("checkValue", "151010") chk2.Attributes.Add("checkValue", "151020") chk3.Attributes.Add("checkValue", "151030") chk4.Attributes.Add("checkValue", "151040")...
1
4527
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 checkbox and I can't get it to default to checked. I tried radiobuttons and experienced the same result.. can't start them as checked. The really frustrating thing is that I set the attributes of other input controls in the Init() with no problem. ...
2
3058
by: Adam Knight | last post by:
Hi all, I have a datagrid with a checkbox in one column. The checkbox is set to autopostback and calls a method named UpdateMailSubscribers. The first click on the checkbox cause the page to post but doesn't seem to haven't any affect. It doesn't appear to call the UpdateMailSubscribers method.
0
1754
by: creejohn | last post by:
Hi all-- I'm really stumped here. I have a (c# 2.0) calendar control that loads a menu for each day inside the cell corresponding to that day in the dayrender event. That is all working great. I have no idea how to figure out whether anyone checked any of the boxes, though! I've tried to loop through the controls to see if any are checkboxes, but I can't seem to get "inside" the calendar itself. Any ideas or guidance would be appreciated....
1
6026
by: iderocks | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and when I check the checkbox at runtime nothing happens (checkBoxObj.check is always false). Does anyone have information on how to make this work? Note: I can get it to work inside Page_Load event. I need help in getting it to work in a different event...
0
9991
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11365
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10702
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9904
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8268
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7442
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6231
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4549
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.