CheckBoxList Not Retaining selections

  • Thread starter Brian K. Williams
  • Start date
B

Brian K. Williams

I have a simple CheckBoxList like:

private void setChbSizes(int nProductID)
{
DataSet dsSizes;
dsSizes = dalSportPal.SizesByProductID(nProductID);
if(dsSizes.Tables[0].Rows.Count >= 0)
{
chbSizes.DataSource = dsSizes.Tables[0];
chbSizes.DataTextField = "ItemSize";
chbSizes.DataValueField = "SizeID";
chbSizes.DataBind();
}
}


When I call the following it's always true:
for ( int i=0; i < chbSizes.Items.Count; i++ )
{
if(chbSizes.Items.Selected == false)
{
// Do Something...
}
}

Anyone have a clue as to why my .Selected is always true?
Thanks in advance,
Brian K. Williams
 
E

Eliyahu Goldin

Brian,

Make sure that you call setChbSizes only if IsPostBack is false. Also check
if you enable ViewState.

Eliyahu
 
B

Brian K. Williams

It's always something simple that you just can't at the end of a 15 hour
day. The next morning I noticed that I forgot the !IsPostback, it was
re-writing everything on every post.

Thanks
-Brian

Eliyahu Goldin said:
Brian,

Make sure that you call setChbSizes only if IsPostBack is false. Also check
if you enable ViewState.

Eliyahu

Brian K. Williams said:
I have a simple CheckBoxList like:

private void setChbSizes(int nProductID)
{
DataSet dsSizes;
dsSizes = dalSportPal.SizesByProductID(nProductID);
if(dsSizes.Tables[0].Rows.Count >= 0)
{
chbSizes.DataSource = dsSizes.Tables[0];
chbSizes.DataTextField = "ItemSize";
chbSizes.DataValueField = "SizeID";
chbSizes.DataBind();
}
}


When I call the following it's always true:
for ( int i=0; i < chbSizes.Items.Count; i++ )
{
if(chbSizes.Items.Selected == false)
{
// Do Something...
}
}

Anyone have a clue as to why my .Selected is always true?
Thanks in advance,
Brian K. Williams

 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top