Dropdownlist

D

Douglas Gage

Hi All

I have dropdown list want to look like this

Select Here
A
B
C
D
E

My database has
A
B
C
D

When I bound this to my dropdownlist I have this
A
B
C
D

I would like to know how i can make it look like the one i described above
without inserting "Select Here" into the database. Also I want user has to
pick one value from the dropwdown list, "select here" will be ignored and
user still has to get back to fix it utinl the value they pick is different
from "select here".

Thanks
 
D

Dune

There are 2 ways that I usually go about this:

1)You don't have to insert "Select Here" into the
database, just fake it inside your select statement:

SELECT '-1' AS id
,'Select Here' AS option
UNION
SELECT id
, option
FROM option_table

2)If your datasource is a DataTable, you can add on an
additional row to it:

Dim optionsTable As DataTable
Dim newRow As DataRow

optionsTable = GetAllOptionsFromDB()

' Create new "Select Here" row
newRow = optionsTable.NewRow()
newRow("id") = "-1"
newRow("option") = "Select Here"

' Add new "Select Here" row at the start of the DataTable
optionsTable.Rows.InsertAt(newRow, 0)
ddlOptions.DataSource = optionsTable
ddlOptions.DataBind()



As for making the user keep picking a choice until they
pick something that is not "Select Here", you will need to
use client-side scripting for that...assuming you set the
value for "Select Here" to -1, you can check the value of
the selected item in the drop down list and if it is equal
to -1, show an error message, and if it is not equal to -
1, submit the form as usual.
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top