[英]VB.NET: CheckBoxList - programmatically setting Items as Checked
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. 例如,我传入一个字符串“ 1,5,8”,希望复选框列表中值为1,5,8的3个项目的状态为“ checked = true”。 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
您应该使用选中的属性,选中的属性仅突出显示列表中的某些项目
lst.Items.FindByValue(value).Checked = True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.