how to put a particular value on top of dropdownlist connected to a sql table?

B

Bart

Hi,

i have a dropdownlist connected to a sqldatasource like this:

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Name">
</asp:DropDownList>


What i want is to put a particular value on the top of the dd. I can't use
ORDER BY.

e.g. the table which feeds the dd contains this:
R
D
A

how to put value D on top of the dd?
Thanks
Bart
 
B

bruce barker

i'd use an order by clause.

select name
from mytable
order by case
when name = 'D' then ''
else name
end case

-- bruce (sqlwork.com)
 
B

Bart

Thanks, but i get an error when executing it in Studio Management:
Incorrect syntax near the keyword 'case'.
 
B

bruce barker

simple typo (its just case ... end), you should read the docs:

select name
from mytable
order by case
when name = 'D' then ''
else name
end
 
B

Bart

Thanks, it works now

bruce barker said:
simple typo (its just case ... end), you should read the docs:

select name
from mytable
order by case
when name = 'D' then ''
else name
end
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top