I am using asp and vb to populate a listbox from a SSMS SQL database table. The table contains names and emails. The listbox populates the name just fine. I want to select a name and have it populate 2 textboxes with name and email without using button if
possible. I have tried everything like txtName.text=lbxnames.selecteditem.text and value but the only 1 that works is index but I don't want number. i have tried if statements and for statements but nothing seems to work. I have also tried coding it
to database. Below is code to fill listbox and code to fil textbox.
This code fills listbox
Private Sub FetchName()
LbxNames.Items.Clear()
SQL.AddParam("@name", "%" & txtName.Text & "%")
SQL.ExecQuery("SELECT * " &
"FROM Contacts " &
"WHERE Name LIKE @name;")
If SQL.HasException(True) Then Exit Sub
For Each r As DataRow In SQL.DBDT.Rows
LbxNames.Items.Add(r("Name"))
Next
End Sub
This code is supposed to fill textbox from listbox doesn't work
Private Sub LbxNames_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LbxNames.SelectedIndexChanged
SQL.ExecQuery("SELECT * " &
"FROM Contacts " &
"WHERE Name = '" + LbxNames.SelectedItem.Text + "';")
If SQL.RecordCount < 1 Then Exit Sub
For Each r As DataRow In SQL.DBDT.Rows
txtName.Text = r("Name")
txtTo.Text = r("Email")
Next
End Sub
Any name and email will populate listbox.
if there is anything else let me know.