CheckBoxList Not Retaining selections

  • Thread starter Thread starter Brian K. Williams
  • Start date 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
 
Brian,

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

Eliyahu
 
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

 
Back
Top