Dropdownlist

  • Thread starter Thread starter Douglas Gage
  • Start date Start date
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
 
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.
 
Back
Top