listbox/dataset question

G

Guest

I'm trying to add an extra row (option) above the list that I create via a
dataset.
I've tried adding a datatable to add a row but can't seem to get it to work.
I'd rather keep it as a dataset. Code:

ddrmaapprovby = listbox

Dim dstEmployees As DataSet
Dim dadEmployees As SqlDataAdapter

dstEmployees = New DataSet
SqlConnect = New SqlConnection(ConnectString)
Dim sqlstring As String = "SELECT CONTACT_ID, CONTACT_LNAME + ', ' +
CONTACT_FNAME AS [FULLNAME] FROM CONTACTS WHERE CONTACT_ROLE = 'EMPLOYEE'
ORDER BY [FULLNAME]"
dadEmployees = New SqlDataAdapter(sqlstring, SqlConnect)
dadEmployees.Fill(dstEmployees, "CONTACTS")

'bind
ddrmaapprovby.DataSource = dstEmployees
ddrmaapprovby.DataMember = "CONTACTS"
ddrmaapprovby.DataTextField = "FULLNAME"
ddrmaapprovby.DataValueField = "CONTACT_ID"
ddrmaapprovby.DataBind()

I want to put in an option like text = (please select) and the value be
blank ("")

thanx.
 
R

Rob

After your call to DataBind() add this line:

ddrmaapprovby.Items.Insert(0, New ListItem("(please select)")

Rob
 
G

Guest

thanx! I added the value to along with the text to this and it works great!
I've been using add and didn't know about insert.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top