Results 1 to 3 of 3

Thread: [RESOLVED] How can I transfer a listbox selected item to a textbox

  1. #1

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Resolved [RESOLVED] How can I transfer a listbox selected item to a textbox

    Hi all!

    I need help getting the value of a selected listbox and transfer it to a textbox.text. I tried everything but seems that I am only getting frustrated.

    There's something definitely wrong with my code:

    Will you guys help me out?

    VB Code:
    1. Imports System.Web.Mail
    2.  
    3. Public Class WebForm1
    4.     Inherits System.Web.UI.Page
    5.  
    6. #Region " Web Form Designer Generated Code "
    7.  
    8.     'This call is required by the Web Form Designer.
    9.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    10.  
    11.     End Sub
    12.     Protected WithEvents Button2 As System.Web.UI.WebControls.Button
    13.     Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
    14.     Protected WithEvents ListBox2 As System.Web.UI.WebControls.ListBox
    15.     Protected WithEvents ListBox3 As System.Web.UI.WebControls.ListBox
    16.  
    17.     'NOTE: The following placeholder declaration is required by the Web Form Designer.
    18.     'Do not delete or move it.
    19.     Private designerPlaceholderDeclaration As System.Object
    20.  
    21.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    22.         'CODEGEN: This method call is required by the Web Form Designer
    23.         'Do not modify it using the code editor.
    24.         InitializeComponent()
    25.     End Sub
    26.  
    27. #End Region
    28.  
    29.     Public Sub AutoGen(ByRef EmailMessage As String)
    30.         Dim RanInteger As Integer
    31.         Randomize()
    32.         RanInteger = Int((3 - 1 + 1) * Rnd() + 1)
    33.         Select Case RanInteger
    34.             Case 1
    35.                 EmailMessage = "Dear Mr. Yehhui," & _
    36.                                "<br>" & _
    37.                                "<br> USCNC has cheap and efficient products! Please visit our site!" & _
    38.                                "<br>" & _
    39.                                "<br> <a href=""\\server\public\IT Folder\Ian Paul\Ian\a.htm"">[url]http://localhost/autoemail/a.htm[/url] </a> "
    40.             Case 2
    41.                 EmailMessage = "Dear Yehhui," & _
    42.                                "<br>" & _
    43.                                "<br> We, at USCNC, have a huge selection of IT products at our disposal." & _
    44.                                "<br>" & _
    45.                                "<br> Please click to this link." & _
    46.                                "<br>" & _
    47.                                "<br> <a href=""\\server\public\IT Folder\Ian Paul\Ian\a.htm"">[url]http://localhost/autoemail/a.htm[/url] </a> "
    48.             Case 3
    49.                 EmailMessage = "Mr. Yehhui," & _
    50.                                "<br>" & _
    51.                                "<br> Want to buy a cool computer but short of cash?" & _
    52.                                "<br>" & _
    53.                                "<br> Then we have the solution for you." & _
    54.                                "<br>" & _
    55.                                "<br> USCNC have a lot of cool computers at affordable prices." & _
    56.                                "<br>" & _
    57.                                "<br> Want to know more?" & _
    58.                                "<br>" & _
    59.                                "<br> Please click this link." & _
    60.                                "<br> <a href=""\\server\public\IT Folder\Ian Paul\Ian\a.htm"">[url]http://localhost/autoemail/a.htm[/url] </a> "
    61.         End Select
    62.     End Sub
    63.  
    64.     Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
    65.         Dim AutoEmail As New MailMessage
    66.         Dim EmailMessage As String
    67.         Dim x As String
    68.         x = ListBox1.SelectedItem.Text  <-- I get stuck here!!!!
    69.         AutoGen(EmailMessage)
    70.         AutoEmail.To = ListBox1.SelectedValue
    71.         AutoEmail.From = "[email protected]"
    72.         AutoEmail.Subject = "Test subject from VB.NET"
    73.         AutoEmail.BodyFormat = MailFormat.Html
    74.         AutoEmail.Body = EmailMessage
    75.         AutoEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25")
    76.         System.Threading.Thread.Sleep(200)
    77.         SmtpMail.SmtpServer = "192.168.11.11"
    78.         System.Threading.Thread.Sleep(200)
    79.         SmtpMail.Send(AutoEmail)
    80.     End Sub
    81.  
    82.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    83.         Dim a As New DataSet
    84.         Dim g As New DataSet
    85.         Dim h As New DataSet
    86.         Dim b As New OleDb.OleDbDataAdapter
    87.         Dim d As New OleDb.OleDbDataAdapter
    88.         Dim f As New OleDb.OleDbDataAdapter
    89.         Dim c As New OleDb.OleDbConnection
    90.         c.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\phil\wa.mdb;Persist Security Info=true"
    91.         c.Open()
    92.         b.SelectCommand = New OleDb.OleDbCommand("SELECT Fname + ' ' + [Emailadd] as expr1 FROM Table1 ;", c)
    93.         d.SelectCommand = New OleDb.OleDbCommand("SELECT Fname + ' ' + EmailS as expr2 FROM Table2 ;", c)
    94.         f.SelectCommand = New OleDb.OleDbCommand("SELECT Product FROM Table3 ;", c)
    95.         b.Fill(a)
    96.         d.Fill(g)
    97.         f.Fill(h)
    98.         ListBox1.DataSource = a
    99.         ListBox1.DataTextField = "expr1"
    100.         ListBox1.DataValueField = "expr1"
    101.         ListBox1.DataBind()
    102.         ListBox2.DataSource = g
    103.         ListBox2.DataTextField = "expr2"
    104.         ListBox2.DataValueField = "expr2"
    105.         ListBox2.DataBind()
    106.         ListBox3.DataSource = h
    107.         ListBox3.DataTextField = "Product"
    108.         ListBox3.DataValueField = "Product"
    109.         ListBox3.DataBind()
    110.         c.Close()
    111.     End Sub
    112.  
    113. End Class

  2. #2

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Talking Re: How can I transfer a listbox selected item to a textbox

    Never mind. I have solved the problem anyway.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How can I transfer a listbox selected item to a textbox

    Don't forget to resolve your thread from the Thread Tools menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width