Adding extra items to a drop down list

P

pitcher17

I'm sure this is really simple to do but I'm at a loss. I have a
dropdownlist object that I have bound to my dataset. That works fine.
However, what I want to do is add an extra static item as the first entry
and then a couple of other static entries further down the list.

Here is my databinding code for the sake of argument... (dropuser is the
name of my dropdownlist)

Dim da As SqlDataAdapter = New SqlDataAdapter(strUsers, conn)
Dim ds As DataSet = New DataSet()
da.Fill(ds, "userTable")
Dim dt As DataTable = ds.Tables("userTable")
dropuser.DataSource = ds.Tables("userTable")
dropuser.DataTextField = "user_name"
dropuser.DataValueField = "user_id"
dropuser.DataBind()


TIA,
Steve
 
P

pitcher17

Thanks for the response. Is 32 the position in the option array or is it
the value? If it is the value how do you specify what position? First
entry is not a problem. I'd just call that before the databind (I assume)?

TIA
Steve

Alvin Bruney said:
Dropdownlist.items.insertat(32,"vapor")

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
pitcher17 said:
I'm sure this is really simple to do but I'm at a loss. I have a
dropdownlist object that I have bound to my dataset. That works fine.
However, what I want to do is add an extra static item as the first entry
and then a couple of other static entries further down the list.

Here is my databinding code for the sake of argument... (dropuser is the
name of my dropdownlist)

Dim da As SqlDataAdapter = New SqlDataAdapter(strUsers, conn)
Dim ds As DataSet = New DataSet()
da.Fill(ds, "userTable")
Dim dt As DataTable = ds.Tables("userTable")
dropuser.DataSource = ds.Tables("userTable")
dropuser.DataTextField = "user_name"
dropuser.DataValueField = "user_id"
dropuser.DataBind()


TIA,
Steve
 
D

Dan Brussee

With all due respect, RTFM, or RTFWS (web site) :) Of course
intellisense could tell you too.

I have found this always to be a two step process.
Items.InsertAt(x, "Text");
Items[x].Value = "blah";



Thanks for the response. Is 32 the position in the option array or is it
the value? If it is the value how do you specify what position? First
entry is not a problem. I'd just call that before the databind (I assume)?

TIA
Steve

Alvin Bruney said:
Dropdownlist.items.insertat(32,"vapor")

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
pitcher17 said:
I'm sure this is really simple to do but I'm at a loss. I have a
dropdownlist object that I have bound to my dataset. That works fine.
However, what I want to do is add an extra static item as the first entry
and then a couple of other static entries further down the list.

Here is my databinding code for the sake of argument... (dropuser is the
name of my dropdownlist)

Dim da As SqlDataAdapter = New SqlDataAdapter(strUsers, conn)
Dim ds As DataSet = New DataSet()
da.Fill(ds, "userTable")
Dim dt As DataTable = ds.Tables("userTable")
dropuser.DataSource = ds.Tables("userTable")
dropuser.DataTextField = "user_name"
dropuser.DataValueField = "user_id"
dropuser.DataBind()


TIA,
Steve
 
A

Alvin Bruney [MVP]

it really doesn't have to be. you can force one line of code
drp1.items.insert(0,new listItem("text","value"));

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
Dan Brussee said:
With all due respect, RTFM, or RTFWS (web site) :) Of course
intellisense could tell you too.

I have found this always to be a two step process.
Items.InsertAt(x, "Text");
Items[x].Value = "blah";



Thanks for the response. Is 32 the position in the option array or is it
the value? If it is the value how do you specify what position? First
entry is not a problem. I'd just call that before the databind (I
assume)?

TIA
Steve

Alvin Bruney said:
Dropdownlist.items.insertat(32,"vapor")

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
I'm sure this is really simple to do but I'm at a loss. I have a
dropdownlist object that I have bound to my dataset. That works fine.
However, what I want to do is add an extra static item as the first entry
and then a couple of other static entries further down the list.

Here is my databinding code for the sake of argument... (dropuser is
the
name of my dropdownlist)

Dim da As SqlDataAdapter = New SqlDataAdapter(strUsers, conn)
Dim ds As DataSet = New DataSet()
da.Fill(ds, "userTable")
Dim dt As DataTable = ds.Tables("userTable")
dropuser.DataSource = ds.Tables("userTable")
dropuser.DataTextField = "user_name"
dropuser.DataValueField = "user_id"
dropuser.DataBind()


TIA,
Steve
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top