Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 03, 2012 12:57 PM by a7Jymoz
Apr 03, 2012 12:42 PM|LINK
I have a checkboxlist that i am populating from a SQL command and when the items are selected they are added into a cookie.
Im having a problem when trying to use the values in the cookie to select the right items when the page loads up. I got the bit of code below and it works fine until the part where i define the ListItem. This always comes up as null even though the values
can be read from the cookie and items with that name are present in the list.
Can anyone help?
HttpCookie cookie = Request.Cookies["CheckBoxList1_SelectedItems"];
if (cookie != null && cookie.Values != null)
foreach (string key in cookie.Values.Keys)
ListItem item = CheckBoxList1.Items.FindByValue(key);
if (item != null)
item.Selected = true;
Apr 03, 2012 12:57 PM|LINK
Nevermind, i've just found what was wrong. I needed to databind the checkboxlist so that the values actually appeared. Seems like it couldn't see them that early on in the load