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

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.Checked == true

//do something

if (CheckBox2.Checked == 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><asp:CheckBox id="CheckBox2" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 64px" runat="server
Text="bbb"></asp:CheckBox><asp:CheckBox id="CheckBox3" style="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 96px" runat="server
Text="ccc"></asp:CheckBox><asp: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 2061
"=?Utf-8?B?YmVib3A=?=" <an*******@discussions.microsoft.com> wrote in
news:7A**********************************@microsof t.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/
"Programming 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 SomeCheckBoxGotClicked(sender as object, e as eventArgs) _
Handles chkBox1.checkChanged, chkBox2.checkChanged, chkBox3.checkChanged

'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.Checkbox).ID
Case "chkBox1"
do something
Case "chkBox2"
do something
Case "chkBox3"
do something
End Select
End Sub
"bebop" <an*******@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.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.Checked == true)
{
//do something
}
if (CheckBox2.Checked == 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><asp:CheckBox id="CheckBox2" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 64px" runat="server" Text="bbb"></asp:CheckBox><asp:CheckBox id="CheckBox3" style="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 96px" runat="server" Text="ccc"></asp:CheckBox><asp: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
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,...
6
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...
3
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...
0
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...
3
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...
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...
2
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...
0
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...
1
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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
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,...

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.