我在数据库表中有这样的数据:
vehicle1 driver1
vehicle1 driver2
vehicle2 driver3
vehicle3 driver4
vehicle3 driver5
vehicle4 driver6
vehicle4 driver7
vehicle4 driver8
我需要在asp.net下拉列表中显示车辆订购的司机。但我需要先显示车辆X的驱动程序,然后动态(以编程方式)设置X.
因此,如果X是vehicle3,我的下拉列表中的数据将如下所示:
**vehicle3 driver4**
**vehicle3 driver5**
vehicle1 driver1
vehicle1 driver2
vehicle2 driver3
vehicle4 driver6
vehicle4 driver7
vehicle4 driver8
有任何建议如何实现这一目标?
答案 0 :(得分:2)
如果您的数据在SQL Server
数据库中,则根据需要选择数据。
SELECT A.Vehicle, A.Driver
FROM (SELECT Vehicle, Driver, CASE @X WHEN Replace(Vehicle,'Vehicle','')
THEN 0 ELSE 1 END AS OrderCol
FROM yourTable ) A
ORDER BY A.OrderCol,A.Vehicle
答案 1 :(得分:0)
使用
从数据库中订购结果
ORDER BY Vehicle, Driver
然后以编程方式在索引0处插入动态项,使它们出现在数据绑定项之前。