With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!
--This Code is used to load the ListBox Public Sub LoadListBox(ByVal lstListBox As ListBox, ByVal strType As String) ' loads a stored proc into a data table 'if Commercial we don't want to load the Factory ListBox 'If Not bolFactory And lstListBox.ID = "lstFactory" Then Exit Sub lstListBox.Items.Clear() SqlConn.Open() Dim SqlCmd As SqlCommand = New SqlCommand() SqlCmd.Connection = SqlConn SqlCmd.CommandText = "Ringgold_Security_Users" SqlCmd.CommandType = CommandType.StoredProcedure 'SqlCmd.Parameters.AddWithValue("UserID", CInt(Me.lblUserID.Text)) 'SqlCmd.Parameters.AddWithValue("Type", strType) ' Create a DataReader Dim theReader As SqlDataReader theReader = SqlCmd.ExecuteReader 'Iterate through the results Dim intTmp As Integer intTmp = 0 While theReader.Read() lstListBox.Items.Add(theReader(0).ToString) lstListBox.Items(intTmp).Value = theReader(0).ToString 'If UCase(theReader(1)) = "Y" Then lstListBox.Items(intTmp).Selected = True intTmp = intTmp + 1 End While SqlCmd = Nothing theReader.Close() theReader = Nothing SqlConn.Close() End Sub --This code here I use to get the value when I select the value on the ListBox. Dim list As String = ListBox1.SelectedItem.Text Nothing Works..
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.