sooter8
asked on
Listbox displaying all items in one selection
I created a multiple line listbox where users could enter multiple file locations into a listbox as separate items and then all of them were saved to the database with commas separating each value.
All went well saving into the database however now i have run into a problem. When you go back and try to edit or view the field again on a different page and the listbox pulls the information from the database it puts everything all in one row with commas separating each value that was inserted.
I'm using Iron Speed if that matters at all...Thanks in advance
add.jpg
edit.jpg
All went well saving into the database however now i have run into a problem. When you go back and try to edit or view the field again on a different page and the listbox pulls the information from the database it puts everything all in one row with commas separating each value that was inserted.
I'm using Iron Speed if that matters at all...Thanks in advance
add.jpg
edit.jpg
what is the code u use to add in to list box..
ASKER
Well it's all automatically generated and actually I don't think it's even editable in iron speed.
This is basically what i see in the .aspx file
<td class="dialog_field_value" ><asp:List Box runat="server" id="UploadedCogoPath" CssClass="field_input" EnableIncrementDecrementBu ttons="Tru e" View="List">
</asp:ListBox></td>
In HTML view i get this
<td class="dialog_field_value" ><GEN:Fiel dValue NAME="UploadedCogoPath" /></td>
This is basically what i see in the .aspx file
<td class="dialog_field_value"
</asp:ListBox></td>
In HTML view i get this
<td class="dialog_field_value"
in vb code ?
ASKER
Ok theres a bunch of different parts. I divided them up with -------------------
If Me.DataSource.UploadedCogo PathSpecif ied Then
Me.PopulateUploadedCogoPat hListBox(M e.DataSour ce.Uploade dCogoPath. ToString() , 20)
-------------------
Else
If Not Me.DataSource.IsCreated Then
Me.PopulateUploadedCogoPat hListBox(T imelogTabl e.Uploaded CogoPath.D efaultValu e, 20)
Else
Me.PopulateUploadedCogoPat hListBox(N othing, 20)
-------------------
Me.DataSource.Parse(GetVal ueSelected PageReques t(Me.Uploa dedCogoPat h), TimelogTable.UploadedCogoP ath)
-------------------
Public Overridable Function CreateWhereClause_Uploaded CogoPathLi stBox() As WhereClause
Return New WhereClause()
End Function
-------------------
' Fill the UploadedCogoPath list.
Protected Overridable Sub PopulateUploadedCogoPathLi stBox( _
ByVal selectedValue As String, _
ByVal maxItems As Integer)
' Create the WHERE clause to filter the list.
Dim wc As WhereClause = Me.CreateWhereClause_Uploa dedCogoPat hListBox()
' Create the ORDER BY clause to sort based on the displayed value.
Dim orderBy As OrderBy = New OrderBy(False, True)
orderBy.Add(TimelogTable.U ploadedCog oPath, OrderByItem.OrderDir.Asc)
' Populate the dropdown list in the sort order specified above.
Me.UploadedCogoPath.Items. Clear()
Dim itemValue As String
For Each itemValue In TimelogTable.GetValues(Tim elogTable. UploadedCo goPath, wc, orderBy, maxItems)
' Create the dropdown list item and add it to the list.
Dim fvalue As String = TimelogTable.UploadedCogoP ath.Format (itemValue )
Dim item As ListItem = New ListItem(fvalue, itemValue)
Me.UploadedCogoPath.Items. Add(item)
Next
' Setup the selected item.
If Not selectedValue Is Nothing AndAlso _
selectedValue.Trim <> "" AndAlso _
Not SetSelectedValue(Me.Upload edCogoPath , selectedValue) AndAlso _
Not MiscUtils.SetSelectedValue (Me.Upload edCogoPath , TimelogTable.UploadedCogoP ath.Format (selectedV alue))Then
Dim fvalue As String = TimelogTable.UploadedCogoP ath.Format (selectedV alue)
Dim item As ListItem = New ListItem(fvalue, selectedValue)
item.Selected = True
Me.UploadedCogoPath.Items. Insert(0, item)
End If
Me.UploadedCogoPath.Items. Insert(0, New ListItem(Page.GetResourceV alue("Txt: PleaseSele ct", "lkhlh"), "--PLEASE_SELECT--"))
End Sub
-------------------
Public ReadOnly Property UploadedCogoPath() As System.Web.UI.WebControls. ListBox
Get
Return CType(BaseClasses.Utils.Mi scUtils.Fi ndControlR ecursively (Me, "UploadedCogoPath"), System.Web.UI.WebControls. ListBox)
End Get
End Property
If Me.DataSource.UploadedCogo
Me.PopulateUploadedCogoPat
-------------------
Else
If Not Me.DataSource.IsCreated Then
Me.PopulateUploadedCogoPat
Else
Me.PopulateUploadedCogoPat
-------------------
Me.DataSource.Parse(GetVal
-------------------
Public Overridable Function CreateWhereClause_Uploaded
Return New WhereClause()
End Function
-------------------
' Fill the UploadedCogoPath list.
Protected Overridable Sub PopulateUploadedCogoPathLi
ByVal selectedValue As String, _
ByVal maxItems As Integer)
' Create the WHERE clause to filter the list.
Dim wc As WhereClause = Me.CreateWhereClause_Uploa
' Create the ORDER BY clause to sort based on the displayed value.
Dim orderBy As OrderBy = New OrderBy(False, True)
orderBy.Add(TimelogTable.U
' Populate the dropdown list in the sort order specified above.
Me.UploadedCogoPath.Items.
Dim itemValue As String
For Each itemValue In TimelogTable.GetValues(Tim
' Create the dropdown list item and add it to the list.
Dim fvalue As String = TimelogTable.UploadedCogoP
Dim item As ListItem = New ListItem(fvalue, itemValue)
Me.UploadedCogoPath.Items.
Next
' Setup the selected item.
If Not selectedValue Is Nothing AndAlso _
selectedValue.Trim <> "" AndAlso _
Not SetSelectedValue(Me.Upload
Not MiscUtils.SetSelectedValue
Dim fvalue As String = TimelogTable.UploadedCogoP
Dim item As ListItem = New ListItem(fvalue, selectedValue)
item.Selected = True
Me.UploadedCogoPath.Items.
End If
Me.UploadedCogoPath.Items.
End Sub
-------------------
Public ReadOnly Property UploadedCogoPath() As System.Web.UI.WebControls.
Get
Return CType(BaseClasses.Utils.Mi
End Get
End Property
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a ton, was almost exactly what i needed.
ASKER
That worked great, the only problem i had was converting from string to char with option strict on. so to fix that i just added a quick convert inside the split.
Thanks for your help!
Thanks for your help!
' Populate the dropdown list in the sort order specified above.
Me.UploadedCogoPath.Items.Clear()
Dim itemValue As String
For Each itemValue In TimelogTable.GetValues(TimelogTable.UploadedCogoPath, wc, orderBy, maxItems)
' Create the dropdown list item and add it to the list.
Dim itemValues() As String = itemValue.Split(Convert.ToChar(","))
For Each iValue As String In itemValues
'splits the CSV-type string into individual values
Dim fValue As String = TimelogTable.UploadedCogoPath.Format(iValue)
Dim item As ListItem = New ListItem(fValue, iValue)
Me.UploadedCogoPath.Items.Add(item)
Next iValue
Next itemValue
ASKER
I actually just realized ONE more tiny problem...it separated all the values just fine, but now it lists ALL of the values not separated and then a copy of them separated in the same listbox. I'm using the code i posted above. Any suggestions?
box.jpg
box.jpg
Check the selectedValue parameter. If it is not found in the list it is being inserted. I suspect that it too is a comma seperated list, not an individual list element. Hence the additional CSV row.