Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi everyone. I am using a webform listbox control on an aspx page. The list is populated with the file names from a particular directory. The weirdness starts in trying get the text of a selected item, I either get an error, a blank string, or a -1 of the SelectedIndex property, no matter which item is selected. This is very strange and doesn't happen in a winforms app, the list acts as expected. Are there any weird settings I am missing when using a webforms listbox?

 

Thanks in advance

James

mod2software

Home of the VB.NET Class Builder Utility - Demo and Full versions available now!

Posted

The problem goes away if I manually populate the list with items from the Items Property Collection builder in the property sheet.

 

maybe how I am populating the list in the first place is the problem? Here is the code...

 

Private Sub PopulateList(ByVal sPath As String)
       Dim dir As Directory
       Dim fileArr() As String
       fileArr = dir.GetFiles(sPath)

       Dim intLoop As Integer

       lstFiles.Items.Clear()
       For intLoop = 0 To fileArr.GetUpperBound(0)
           lstFiles.Items.Add(CStr(fileArr.GetValue(intLoop)))
       Next intLoop
   End Sub

mod2software

Home of the VB.NET Class Builder Utility - Demo and Full versions available now!

Posted

Page Load is empty but the following code is used to populate the listbox, when I use an intermediary collection to hold the file names, then pull them out into the list, the list then behaves as expected...

 

Private Sub PopulateList(ByVal sPath As String)
       Dim dir As Directory
       Dim fileArr() As String
       fileArr = dir.GetFiles(sPath)

       Dim intLoop As Integer
       Dim intEnd As Integer = fileArr.GetUpperBound(0)
       Dim colFileNames As New Collection


       lstFiles.Items.Clear()

       For intLoop = 0 To intEnd
           colFileNames.Add(CStr(fileArr.GetValue(intLoop)))
       Next intLoop

       Dim strLooper As String
       For Each strLooper In colFileNames
           lstFiles.Items.Add(strLooper)
       Next

       colFileNames = Nothing
   End Sub

 

strange ?

mod2software

Home of the VB.NET Class Builder Utility - Demo and Full versions available now!

Posted

The postback issue mentioned above is almost surely your problem. I have this with datagrids quite often. I use a hidden html control to hold the value I want to keep and actually use that value when I execute code. I populate the html control with the OnSelectedItemChange event.

 

HTH

 

Eva

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...