CheckBoxList

T

Trond

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.???==true)

{


checksum += int.Parse(CheckBoxList1.Items.Value);

}

}

Any hint that can help me out is appreciated.

Best regards Trond
 
T

Trond

I figured it out after some thinking. Here is solution
for(int i=0;i<CheckBoxList1.Items.Count;i++)
{
if(CheckBoxList1.Items.Selected)
{
checksum += int.Parse(CheckBoxList1.Items.Value);
}
}

Best regards Trond
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top