DropDownList Fill

T

tshad

I am trying to fill my DropDownList (actually a few of them) with data from
my sql table. I am calling Stored procedures for all of them.

I would like to use the first line as a place holder that tells them what to
pick - "Minimum Education Level" - for instance.

At the moment I do something like the following to fill the drop downs:

*****************************************************************
Sub GetExperience(sender As Object, e As System.EventArgs)
Dim emailReader As SqlDataReader
trace.warn("inside GetExperience")
Dim ConnectionString as String
=System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_ftso")
Dim objConn as New SqlConnection (ConnectionString)
Dim CommandText as String = "Exec GetExperienceLevel"
Dim objCmd as New SqlCommand(CommandText,objConn)
objConn.Open()

ExperienceLevel.DataSource=objCmd.ExecuteReader
ExperienceLevel.DataTextField= "Description"
ExperienceLevel.DataValueField="EducationLevelID"
ExperienceLevel.databind()
trace.warn("exiting GetZipCodes")
end sub
*******************************************************************

Is there a way to tell it to start filling at item(1) and put a description
in item(0)?

Thanks,

Tom
 
R

Raterus

after you call .DataBind on the DropDownList, you can do the following to put an item at the beginning

ExperienceLevel.Items.Insert(0, "Some Description")

--Michael

Dim li as listitem = new listitem("Some Description
 
T

tshad

after you call .DataBind on the DropDownList, you can do the following to
put an item at the beginning

ExperienceLevel.Items.Insert(0, "Some Description")

That was what I was looking for.

Thanks,

Tom

--Michael

Dim li as listitem = new listitem("Some Description
 
T

tshad

tshad said:
after you call .DataBind on the DropDownList, you can do the following to
put an item at the beginning

ExperienceLevel.Items.Insert(0, "Some Description")

One other question.

Why doesn't it have to be:

ExperienceLevel.Items.Insert(0, new ListItem("Some Description"))

Are they the same thing?

Thanks,

Tom
 

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

Top