Re: Using the DataTextField and DataValue Field in a ListBox
- From: "Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldDinN@xxxxxxxxxxxx>
- Date: Wed, 20 Sep 2006 12:45:26 +0200
datavaluefield is supposed to be set to the name of the field. Your code
assigns to it the value of the field. And anyway, datavaluefield is used
only in databinding and you are not using any databinding, you are adding
items programatically.
You should do something like
ListBox1.Items.Add(New ListItem (NameDataReader.GetValue(0) & " " &
NameDataReader.GetValue(1), NameDataReader.GetValue(2)))
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"l7alabeh" <l7alabeh@xxxxxxxxx> wrote in message
news:1158744418.462352.18180@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
This is the code:
Sub ListBoxBind()
connstrconf.ConnectionString = strcnnconf
Dim NameDataReader As OleDbDataReader
Dim NameOleDbCommand As OleDbCommand
NameOleDbCommand = New OleDbCommand("select first_name,
last_name, dbid from cfg_person", connstrconf)
connstrconf.Open()
NameDataReader = NameOleDbCommand.ExecuteReader()
Do While (NameDataReader.Read())
ListBox1.Items.Add(NameDataReader.GetValue(0) & " " &
NameDataReader.GetValue(1))
ListBox1.datavaluefield = NameDataReader.GetValue(2)
Loop
NameDataReader.Close()
connstrconf.Close()
End Sub
.
- Follow-Ups:
- Re: Using the DataTextField and DataValue Field in a ListBox
- From: l7alabeh
- Re: Using the DataTextField and DataValue Field in a ListBox
- References:
- Using the DataTextField and DataValue Field in a ListBox
- From: l7alabeh
- Re: Using the DataTextField and DataValue Field in a ListBox
- From: Eliyahu Goldin
- Re: Using the DataTextField and DataValue Field in a ListBox
- From: l7alabeh
- Using the DataTextField and DataValue Field in a ListBox
- Prev by Date: Re: ASP.NET using My.Settings
- Next by Date: Problems when uploading ASPNETDB.MDF to production server
- Previous by thread: Re: Using the DataTextField and DataValue Field in a ListBox
- Next by thread: Re: Using the DataTextField and DataValue Field in a ListBox
- Index(es):