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

Home Posts Topics Members FAQ

the selected values in my checkboxlist are not adding correctly

29 New Member
I am trying to add only my selected values but its only adding the first selected value in my list repeatedly to the amount of selected items. can someone help me with this?

for example, lets say I check off 2 in my list. than I check off three other boxes are inline after 2's box in my list not before. no matter what value is in those boxes I still get 8. 2+2+2+2


Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.         lblAnswer.Text = ""
  3.         ListBox1.Items.Clear()
  4.         ''add up prices from list 
  5.         Dim total As Decimal
  6.         Dim i As Int32
  7.  
  8.         For i = 0 To CheckBoxList1.Items.Count - 1
  9.             If CheckBoxList1.Items(i).Selected Then
  10.                 total += Decimal.Parse(CDec(CheckBoxList1.SelectedValue.ToString))
  11.                 ListBox1.Items.Add(CheckBoxList1.SelectedValue)
  12.             End If
  13.  
  14.         Next
  15.         lblAnswer.Text = total
  16.  
  17.     End Sub
  18. End Class
Mar 13 '08 #1
1 1555
misza
13 New Member
Hi,

what you're doing wrong is that you're using CheckBoxList1.SelectedValue property for getting the value - it's showing list's first (of the lowest index) selected value instead of a "current iteration";

pls take a look at this example (from msdn, slightly modified) of iterating through Checkboxlist's items

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. For i = 0 To checkboxlist1.Items.Count - 1
  3.     If checkboxlist1.Items(i).Selected Then
  4.        ' the value you're looking for is in checkboxlist1.Items(i).Text
  5.     End If
  6. Next
  7.  
hope this helps,
M.
Mar 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Kumar | last post by:
Hi , I am using the article code shown in below url: http://www.codeproject.com/aspnet/xmlxsltransformer.asp?df=100&forumid=118504&select=1170328 This article is very cool feature. I...
0
by: Francois Verbeeck | last post by:
Dear UseNet readers, Does anyone have any idea on how to colorize selected checkbox in checkboxlist control ? I've quite a huge checkboxlist (approximatively one full screen) and, to improve...
4
by: krzysiek | last post by:
hello, i have several radiolists and checkboxlist that are generated dinamicly based on datasource. So frankly speaking i don't know names and number of that web controls cose they are always...
0
by: Boris | last post by:
When I dynamically create CheckButtonList, I add ListItem(s) to my CheckButtonList object chkList chkList.Items.Add(new ListItem("My Text", "My Value")); The resulting HTML doesn't contain...
5
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
1
by: sheenaa | last post by:
Hello friends, I m using ASP.NET with C# 2005 and SQL SERVER 2005 for the ASP.Net Website. I m using sqldatasource to connect and retrieve the data from database and then it displays the data...
1
by: momenee | last post by:
Problem: How to set the Selected property of items in a CheckBoxList in the EditItemTemplate of a FormView control that has been populated initially using an ObjectDataSource. I have a column in a...
1
by: cluce | last post by:
I have some prices listed in a checkboxlist that I am trying to add up. First I was going to add the mto a list box and add them up that way but I forgot how to do it. Its been awhile and I dont have...
1
by: cluce | last post by:
I am trying to add only my selected values but its only adding the first selected value in my list repeatedly to the amount of selected items. can someone help me with this? for example, lets say...
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
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
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,...
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
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.