469,590 Members | 1,996 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

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 2419
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Bryce Budd | last post: by
4 posts views Thread by dm_dal | last post: by
4 posts views Thread by Shaul Feldman | last post: by
5 posts views Thread by Eirik Eldorsen | last post: by
3 posts views Thread by I am Sam | last post: by
4 posts views Thread by Patrick.O.Ige | last post: by
2 posts views Thread by Patrick.O.Ige | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.