Solved

Listbox displaying all items in one selection

Posted on 2008-06-12
9
962 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:sooter8
  • 5
  • 2
  • 2
9 Comments
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 21774272
what is the code u use to add in to list box..
0
 

Author Comment

by:sooter8
ID: 21774350
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:ListBox runat="server" id="UploadedCogoPath" CssClass="field_input" EnableIncrementDecrementButtons="True" View="List">
                                                                                    </asp:ListBox></td>

In HTML view i get this
<td class="dialog_field_value"><GEN:FieldValue NAME="UploadedCogoPath" /></td>
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 21774466
in vb code ?
0
 

Author Comment

by:sooter8
ID: 21774562
Ok theres a bunch of different parts. I divided them up with -------------------

  If Me.DataSource.UploadedCogoPathSpecified Then
                Me.PopulateUploadedCogoPathListBox(Me.DataSource.UploadedCogoPath.ToString(), 20)
-------------------
            Else
                If Not Me.DataSource.IsCreated Then
                    Me.PopulateUploadedCogoPathListBox(TimelogTable.UploadedCogoPath.DefaultValue, 20)
                   Else
 Me.PopulateUploadedCogoPathListBox(Nothing, 20)
-------------------
            Me.DataSource.Parse(GetValueSelectedPageRequest(Me.UploadedCogoPath), TimelogTable.UploadedCogoPath)
-------------------
        Public Overridable Function CreateWhereClause_UploadedCogoPathListBox() As WhereClause
            Return New WhereClause()
        End Function
-------------------

        ' Fill the UploadedCogoPath list.
        Protected Overridable Sub PopulateUploadedCogoPathListBox( _
                ByVal selectedValue As String, _
                ByVal maxItems As Integer)
                 
            ' Create the WHERE clause to filter the list.
            Dim wc As WhereClause  = Me.CreateWhereClause_UploadedCogoPathListBox()

            ' Create the ORDER BY clause to sort based on the displayed value.
            Dim orderBy As OrderBy = New OrderBy(False, True)
            orderBy.Add(TimelogTable.UploadedCogoPath, 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(TimelogTable.UploadedCogoPath, wc, orderBy, maxItems)
                ' Create the dropdown list item and add it to the list.
                Dim fvalue As String = TimelogTable.UploadedCogoPath.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.UploadedCogoPath, selectedValue) AndAlso _
                Not MiscUtils.SetSelectedValue(Me.UploadedCogoPath, TimelogTable.UploadedCogoPath.Format(selectedValue))Then
                Dim fvalue As String = TimelogTable.UploadedCogoPath.Format(selectedValue)
                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.GetResourceValue("Txt:PleaseSelect", "lkhlh"), "--PLEASE_SELECT--"))
                 
        End Sub
-------------------
  Public ReadOnly Property UploadedCogoPath() As System.Web.UI.WebControls.ListBox
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "UploadedCogoPath"), System.Web.UI.WebControls.ListBox)
            End Get
        End Property
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 16

Accepted Solution

by:
GreymanMSC earned 125 total points
ID: 21776281
How were the items "saved to the database with commas separating each value", and how are you retreiving them to fill TimelogTable?

Because, if you are storing them as a single comma seperated string, you need to spit that string on retrieval.
   ' 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(",")

       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

Open in new window

0
 

Author Closing Comment

by:sooter8
ID: 31466763
Thanks a ton, was almost exactly what i needed.
0
 

Author Comment

by:sooter8
ID: 21778889
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!
            ' 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

Open in new window

0
 

Author Comment

by:sooter8
ID: 21779209
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
0
 
LVL 16

Expert Comment

by:GreymanMSC
ID: 21790067
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.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb.net checkbox 7 41
Runtime Error 2 28
Receiving a string from a WebService Push 21 37
Automated testing suggestions? 2 28
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now