Tuesday, December 12, 2006

Function which returns the "Selected Texts" of a multiselect listbox

Function ReturnSelectedTexts(ByVal objControlName As Object) As String
'This function returns the selected texts of the multiselect listbox
Dim strSelectedTexts As String
Dim lstItem As ListItem
For Each lstItem In objControlName.items
If lstItem.Selected = True Then
strSelectedTexts = strSelectedTexts & lstItem.Text & ", "
End If
Next
strSelectedTexts = Trim(strSelectedTexts)
strSelectedTexts = Left(strSelectedTexts, Len(strSelectedTexts) - 1)
Return strSelectedTexts
End Function

'----Usage
lblSearchCriterias.Text = "Email verified: " & ReturnSelectedTexts(lstEmailVerified)

'--It will give the selected items as comma separated.

Cheers
Rajesh Sivaraman.

No comments: