[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

CheckBoxList always returns Checked=false

(Kerry Whelan)

1/21/2003 10:07:00 PM

Hi,

I am struggling with the CheckBoxList control. When I add items to the
CheckBoxList control at design time and select some of the boxes at
runtime, the selected boxes return Checked=true and I can deal with
them as I wish. If I add items to the CheckBoxList programmatically at
runtime and then use the same code to access the Checked attribute,
all boxes return checked=false.


I use a dataReader to bind the values and names to the CheckBoxList:-

CheckBoxList1.DataSource=dataReader;
CheckBoxList1.DataBind();

The following code is used to find which boxes are selected:-

foreach(ListItem li in CheckBoxList1.Items)
{
if(li.Selected==true)
{
//code here
}
}

Any help would be greatly appreciated.

Thankyou,

Kerry Whelan
1 Answer

Jim Ross [MVP]

1/13/2003 7:57:00 PM

0

You need to add those items programatically in PageInit or they won't
exist for the viewstate to restore their values.

whelan_kerry@hotmail.com (Kerry Whelan) wrote:

>Hi,
>
>I am struggling with the CheckBoxList control. When I add items to the
>CheckBoxList control at design time and select some of the boxes at
>runtime, the selected boxes return Checked=true and I can deal with
>them as I wish. If I add items to the CheckBoxList programmatically at
>runtime and then use the same code to access the Checked attribute,
>all boxes return checked=false.
>
>
>I use a dataReader to bind the values and names to the CheckBoxList:-
>
>CheckBoxList1.DataSource=dataReader;
>CheckBoxList1.DataBind();
>
>The following code is used to find which boxes are selected:-
>
>foreach(ListItem li in CheckBoxList1.Items)
>{
> if(li.Selected==true)
> {
> //code here
> }
>}
>
>Any help would be greatly appreciated.
>
>Thankyou,
>
>Kerry Whelan

Jim Ross
MS MVP [ASP.NET][VC/MFC emeritus]

To send email, change 'lotsofspamthroughhere' to 'msn' but please ask all questions in the newsgroups, not via private mail