DropDownList datalist extension

  • Thread starter Thread starter Przemo
  • Start date Start date
P

Przemo

Hi,

I have a DropDownList, which is based on a DataTable
generated from SQLServer. It consists of two fields: ID
and Name.
ID starts from "1"
I Would like to add a special row to my DropDownList with
ID=0 abd Name="Please select".

Any suggestions?

Thank you.
 
I got it.
Sorry for disturbing!

Dim dr As DataRow = dt.NewRow()
dr(0) = Int32.MinValue
dr(1) = "z"
dt.Rows.InsertAt(dr, 0)
DropDownList1.DataSource = dt

Przemo
 
Simple, I use a Union Query as the basis of my recordset
stSQL= "SELECT 0 AS ID, 'Please Select' As Name FROM tblYourTable
UNION SELECT ID, Name FROM tblYourTable
ORDER BY ID"

Or if you want to sort by name:
stSQL= "SELECT 0 AS ID, 'Please Select' AS Name, '' AS Sort FROM
tblYourTable
UNION SELECT ID, Name, Name AS Sort FROM tblYourTable
ORDER BY Sort"
 
Back
Top