K
Karl Seguin
Bienwell:
That's how you have to do it...selectedValue only returns the first
value...you need to loop throught hte items and get each value...
a couple comments on your code in general. FieldList.ITems.Count and
FieldList.SelectedIndex don't need to be CINT'ed...those are already int
values....Also, many people would say that a foreach is much more readable.
Two final thoughts, if you are expecting a lot of values, you should
probably use a StringBuilder...and you should make this a utility
function...so my code would look like:
Sub Button1_Click...
dim selectedValues = Utility.GetListControlSelectedValues(FieldList)
end sub
end class
Public Class Utility
Public Shared Function GetListControlSelectedValues(ByVal control As
ListControl) As String
If Control Is Nothing Then
Return ""
End If
Dim str As New System.Text.StringBuilder
For Each item As ListItem In control.Items
If item.Selected = True Then
str.Append(item.Text)
End If
Next
Return str.ToString()
End Function
End Class
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
That's how you have to do it...selectedValue only returns the first
value...you need to loop throught hte items and get each value...
a couple comments on your code in general. FieldList.ITems.Count and
FieldList.SelectedIndex don't need to be CINT'ed...those are already int
values....Also, many people would say that a foreach is much more readable.
Two final thoughts, if you are expecting a lot of values, you should
probably use a StringBuilder...and you should make this a utility
function...so my code would look like:
Sub Button1_Click...
dim selectedValues = Utility.GetListControlSelectedValues(FieldList)
end sub
end class
Public Class Utility
Public Shared Function GetListControlSelectedValues(ByVal control As
ListControl) As String
If Control Is Nothing Then
Return ""
End If
Dim str As New System.Text.StringBuilder
For Each item As ListItem In control.Items
If item.Selected = True Then
str.Append(item.Text)
End If
Next
Return str.ToString()
End Function
End Class
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)