id, company, contact where id is actually the primary key of the row.
I'd like to make a list box which displays only the company and contact. When the user clicks on one of the choices, the code in the codebehind page would be able to identify the id of the selected name.
How can this be done in asp.net.
Many thanks
MIke Thomas
You should modify your Select string so that it concatenates company and contact into one field. Then use the DataTextField and the DataValueField properties to bind to your listbox:
'SQL
Dim strSQL As String = "SELECT id, company + ": " + contact As CompanyAndContact From Companies"'open a connection and populate a datareader with a command object...
myListBox.DataSource = myReader ' a SqlDataReader...
myListBox.DataTextField = "CompanyAndContact"
myListBox.DataValueField = "id"
After this, you can get the id from the SelectedItem.Value property of your listbox.
The only problem with this solution is that the formatting of your listbox may not look very good.
0 comments:
Post a Comment