473,473 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Small problem with my code

Please look at this code .. this will add the values of all 'checked' boxes
(check box list control) into an array .. the problem is its adding the
values twice.
for eg: If I selected 2, 3 on the page the array is getting values ..
2,2,3,3. It should be getting 2,3. What is the error?

foreach ( ListItem item in LayersCheckBoxList.Items )
{
int j = LayerNameList1.Count ;
if ( item.Selected )
{
for (int i =0; i<j; i++ )
{
if (LayersCheckBoxList.Items[i].Selected)
{
LayerNameList2.Add(LayersCheckBoxList.Items[i]);
}
}
}
}

Any help would be greatly appreciated !

Thanks
Steven
Nov 16 '05 #1
2 1356
Not sure what LayerNameList1 and LayerNameList2 are in the context of this
code.

What is the purpose of the inner loop? If you simply want to add them to an
array, then why not something like:

ArrayList al = new ArrayList();
foreach( ListItem item in LayersCheckBoxList.Items )
{
if( item.Selected )
{
al.Add(item);
}
}

"Steven" <counterball_20122@_hotmail.com> wrote in message
news:#9**************@TK2MSFTNGP15.phx.gbl...
Please look at this code .. this will add the values of all 'checked' boxes (check box list control) into an array .. the problem is its adding the
values twice.
for eg: If I selected 2, 3 on the page the array is getting values ..
2,2,3,3. It should be getting 2,3. What is the error?

foreach ( ListItem item in LayersCheckBoxList.Items )
{
int j = LayerNameList1.Count ;
if ( item.Selected )
{
for (int i =0; i<j; i++ )
{
if (LayersCheckBoxList.Items[i].Selected)
{
LayerNameList2.Add(LayersCheckBoxList.Items[i]);
}
}
}
}

Any help would be greatly appreciated !

Thanks
Steven

Nov 16 '05 #2
Thanks Peter .. it works .. !

regards
steven

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:OR****************@tk2msftngp13.phx.gbl...
Not sure what LayerNameList1 and LayerNameList2 are in the context of this
code.

What is the purpose of the inner loop? If you simply want to add them to
an
array, then why not something like:

ArrayList al = new ArrayList();
foreach( ListItem item in LayersCheckBoxList.Items )
{
if( item.Selected )
{
al.Add(item);
}
}

"Steven" <counterball_20122@_hotmail.com> wrote in message
news:#9**************@TK2MSFTNGP15.phx.gbl...
Please look at this code .. this will add the values of all 'checked'

boxes
(check box list control) into an array .. the problem is its adding the
values twice.
for eg: If I selected 2, 3 on the page the array is getting values ..
2,2,3,3. It should be getting 2,3. What is the error?

foreach ( ListItem item in LayersCheckBoxList.Items )
{
int j = LayerNameList1.Count ;
if ( item.Selected )
{
for (int i =0; i<j; i++ )
{
if (LayersCheckBoxList.Items[i].Selected)
{
LayerNameList2.Add(LayersCheckBoxList.Items[i]);
}
}
}
}

Any help would be greatly appreciated !

Thanks
Steven


Nov 16 '05 #3

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

Similar topics

2
by: Dave Brueck | last post by:
Below is some information I collected from a *small* project in which I wrote a Python version of a Java application. I share this info only as a data point (rather than trying to say this data...
7
by: Randall Parker | last post by:
Using IE 6.x (whatever is the latest) on Windows 2000. For these two CSS definitions if I remove the 2 lines that have the "mso-" font family definitions (mso-fareast-font-family, and...
2
by: Luc | last post by:
I saw a few posts on this newsgroup about it but nothing to help me resolve this problem: We designed a window in .NET on a platform using small fonts (120 ppp). But this window will run on...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
1
by: jason | last post by:
In a small shop with 3 .net developers. What would typically be considered a good deployment practice if there is a chance of developers might be working on the same websites at the same time? ...
17
by: Brian Blais | last post by:
Hello, I have a couple of classes where I teach introductory programming using Python. What I would love to have is for the students to go through a lot of very small programs, to learn the...
8
by: Joe | last post by:
Hi trying to write some code to determine if user has large/small fonts set on PC thought this would work but it didn't Any suggestions??? Thanks Graphics g = Graphics.FromHwnd(this.Handle);
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
4
by: asedt | last post by:
What do you think of my process model for small projects - "one person projects". Do you have any good ideas or improvements? Did anyone find it useful? This is a simple model that I used when I...
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
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,...
1
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
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...
1
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...
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
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.