You are trying to do two things at once, your logic will only allow
one box to be checked, the one that has the value = the last item in
split.
Adding a break command should work
if(item.Value == s)
{
item.Selected = true;
break;
}
or you can do a little less work...
private void ClearSelectedItems()
{
foreach(ListItem li in cblStaff.Items)
li.Selected = false;
}
//check items that have values in the supplied array
private void CheckEmDano(string[] split)
{
//Don't need this if you rebind the list on every postback
ClearSelectedItems();
ListItem li;
foreach(string s in split)
{
li = cblStaff.Items.FindByValue(s);
if(li != null)
li.Selected = true;
}
}
On 6/14/05, Ryan Olshan <[EMAIL PROTECTED]> wrote:
> I am having problems taking a string array and checking off items in a
> checkbox list. String starts off in database as a csv value (i.e. 1,3,5). I
> used split.string for the character ',' but I still cannot get it to work.
> It only checks off one value in the CheckBoxList.
>
> if(!(System.Convert.IsDBNull(dataReader["StaffAssigned"])))
> {
> string strStaff = (string) dataReader["StaffAssigned"];
>
> string [] split = strStaff.Split(new char[] {','});
>
> foreach(ListItem item in cblStaff.Items)
> {
> foreach(string s in split)
> {
> if(item.Value == s)
> item.Selected = true;
> else
> item.Selected = false;
> }
> }
> }
>
>
> --
> Thank you,
> Ryan Olshan
> TeraNet Systems
> http://www.teranetsystems.com
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/