1

I pass in comma separated values to this function, and check items in a checkboxlist according to the values. But there are no items checked after the function call.

For example, I pass in a string "1,5,8", hoping the 3 items with value of 1,5,8 in the checkboxlist will get "checked = true" status. But they don't.

Private Sub GetListValuesFromCommaSeparatedValueString(ByRef lst As CheckBoxList, s As String)
    If IsNothing(s) Or s = "" Then
        Exit Sub
    End If

    Dim array = s.Split(",")

    For Each value As String In array
        lst.Items.FindByValue(value).Selected = True
    Next

End Sub
3
  • It's webform. Sorry forgot to mention. Commented Jan 28, 2016 at 20:35
  • I'm sorry the checkboxlist databind happened after the function call. That's why it was not working. My bad. Commented Jan 28, 2016 at 20:41
  • 1
    @Cal It would be nice if you could take some time edit your question and improve it with "page part" of code and make it more precise then make answer to your own question as it would be great to someone who will run into same or similar problem and find your question - mention of solution to your problem only in comment is not best idea Commented Jan 29, 2016 at 0:18

2 Answers 2

2

You'd want the Checked property of CheckBox not Selected.

For Each value As String In array
    lst.Items.FindByValue(value).Checked = True
Next

More info on Checked.

Sign up to request clarification or add additional context in comments.

2 Comments

It's webform, Checked property is not available.
I'm not an ASP guy, but a quick google turned up this: forums.asp.net/t/…
1

You should use checked property, selected highlights only certain item on list

lst.Items.FindByValue(value).Checked = True

2 Comments

It's webform, Checked property is not available.
@Cal Next time try to provide as much details as it is possible, including more complete code samples, description and tags. In such case you will be able to get more detailed and faster help with your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.