F
Fabio Visin
I'm working with a DetailsView in edit mode. One of its controls is a
listbox with selectionmode set to multiple. I retrieve the the data for the
detailview from a database so I use this code:
<asp:ListBox ID="ListBoxPaese" runat="server" DataSourceID="PaesiDataSource"
DataTextField="Extended_name_It" DataValueField="Code2Char" Rows="8"
SelectionMode="Multiple" SelectedValue='<%# Eval("Paese") %>'>
</asp:ListBox>
The value "Paese" (country) in my table is a string with comma to separate
the countries (i.e. "al" or "al,ba,bg"); in the first case I have no problem
but when I expect to see more listitem selected, like se second case, I
obviously get en error.
I try with a function to elaborate the data before the binding but with no
result. So my new listbox code is:
<asp:ListBox ID="ListBoxPaese" runat="server" DataSourceID="PaesiDataSource"
DataTextField="Extended_name_It" DataValueField="Code2Char" Rows="8"
SelectionMode="Multiple" SelectedValue='<%#
CreateListItem(Eval("Paese")) %>'>
</asp:ListBox>
Function CreateListItem(ByVal elenco As String) As ListItemCollection
Dim listItems As New ListItemCollection
Dim elencoS As String() = Split(elenco, ",")
For i As Integer = 0 To elencoS.Length - 1
listItems.Add(elencoS(i))
Next
Return listItems
End Function
How can I solve my problem?
Thanks
Fabio
listbox with selectionmode set to multiple. I retrieve the the data for the
detailview from a database so I use this code:
<asp:ListBox ID="ListBoxPaese" runat="server" DataSourceID="PaesiDataSource"
DataTextField="Extended_name_It" DataValueField="Code2Char" Rows="8"
SelectionMode="Multiple" SelectedValue='<%# Eval("Paese") %>'>
</asp:ListBox>
The value "Paese" (country) in my table is a string with comma to separate
the countries (i.e. "al" or "al,ba,bg"); in the first case I have no problem
but when I expect to see more listitem selected, like se second case, I
obviously get en error.
I try with a function to elaborate the data before the binding but with no
result. So my new listbox code is:
<asp:ListBox ID="ListBoxPaese" runat="server" DataSourceID="PaesiDataSource"
DataTextField="Extended_name_It" DataValueField="Code2Char" Rows="8"
SelectionMode="Multiple" SelectedValue='<%#
CreateListItem(Eval("Paese")) %>'>
</asp:ListBox>
Function CreateListItem(ByVal elenco As String) As ListItemCollection
Dim listItems As New ListItemCollection
Dim elencoS As String() = Split(elenco, ",")
For i As Integer = 0 To elencoS.Length - 1
listItems.Add(elencoS(i))
Next
Return listItems
End Function
How can I solve my problem?
Thanks
Fabio