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

CheckBoxList

I have a CheckBoxList on my ASP.NET page. It is populated from a dataset:
DataSet dsType = new DataSet();

dsType = rmController.GetStatusMessages();

CheckBoxList1.DataSource = dsType.Tables[0];

CheckBoxList1.DataTextField =
dsType.Tables[0].Columns["Status"].ColumnName.ToString();

CheckBoxList1.DataValueField=
dsType.Tables[0].Columns["IDStatus"].ColumnName.ToString();

CheckBoxList1.DataBind();

----------------------------------------------------------

So far so good

Then the user can select 1 or more options in CheckBoxList1 that in this
case counts 4 items. IDStatus is an integer and Status is the text:
1 option1
2 option2
4 option3
8 option4

SO if the user selects option2 and option4 i want to be able to return 2 + 8
(10).

I tried to fig out how i can test if an item is checked or not. It is easy
in a winform but the ASP.NET control is not that easy :-)
Here is code that i have been playing with:

for (int i = 0; i < CheckBoxList1.Items.Count; i++)

{

if (CheckBoxList1.Items[i].???==true)

{
checksum += int.Parse(CheckBoxList1.Items[i].Value);

}

}

Any hint that can help me out is appreciated.

Best regards Trond
Nov 19 '05 #1
1 2588
I figured it out after some thinking. Here is solution
for(int i=0;i<CheckBoxList1.Items.Count;i++)
{
if(CheckBoxList1.Items[i].Selected)
{
checksum += int.Parse(CheckBoxList1.Items[i].Value);
}
}

Best regards Trond

"Trond" <tr***@montanis.com> wrote in message
news:O1**************@TK2MSFTNGP14.phx.gbl...
I have a CheckBoxList on my ASP.NET page. It is populated from a dataset:
DataSet dsType = new DataSet();

dsType = rmController.GetStatusMessages();

CheckBoxList1.DataSource = dsType.Tables[0];

CheckBoxList1.DataTextField =
dsType.Tables[0].Columns["Status"].ColumnName.ToString();

CheckBoxList1.DataValueField=
dsType.Tables[0].Columns["IDStatus"].ColumnName.ToString();

CheckBoxList1.DataBind();

----------------------------------------------------------

So far so good

Then the user can select 1 or more options in CheckBoxList1 that in this
case counts 4 items. IDStatus is an integer and Status is the text:
1 option1
2 option2
4 option3
8 option4

SO if the user selects option2 and option4 i want to be able to return 2 +
8 (10).

I tried to fig out how i can test if an item is checked or not. It is easy
in a winform but the ASP.NET control is not that easy :-)
Here is code that i have been playing with:

for (int i = 0; i < CheckBoxList1.Items.Count; i++)

{

if (CheckBoxList1.Items[i].???==true)

{
checksum += int.Parse(CheckBoxList1.Items[i].Value);

}

}

Any hint that can help me out is appreciated.

Best regards Trond

Nov 19 '05 #2

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

Similar topics

0
by: Bryce Budd | last post by:
Hello All, I've been a taker of information from newsgroups for a long time and thought I'd finally make a contribution back to the community whose supported me when I've needed it. After all...
4
by: dm_dal | last post by:
Is there a know issue surrounding the CheckBoxList control and it's viewstate? When my control is created, it's ListItems are checked as needed, but on a postback, they loose their Selected...
4
by: Shaul Feldman | last post by:
Hello, I have something really awkward at work - fighting with CheckBoxList... How can I define CSS for ListItem in CheckBoxList programmatically. I add CheckBoxList's Items on the fly, something...
5
by: Eirik Eldorsen | last post by:
I'm trying to code a reapter that for each listelement show a checkboxlist. I'm almost there. The only thing I can't figure out is how to set the ID of the checkboxlists. This is my code:...
3
by: I am Sam | last post by:
I keep getting the following error message when I try to iterate through a CheckBoxList control: Object reference not set to an instance of an object. Description: An unhandled exception...
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...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
2
by: Patrick.O.Ige | last post by:
I have some boolean value(1 or 0 ) in a table and i want a databinded CheckBoxList to present the selected values on the page.. With CheckBox i know i can se the Checked property like so :-...
0
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView...
0
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.