嗨,我有一个下拉列表,我试图将第一个列表项设置为值null,将文本设置为' ---'所以当选择' ---'从下拉列表中,该值将为null,因此使用像这样的Sql数据源在.aspx
页面中成功执行此操作
<asp:SqlDataSource ID="sqsGetAllJobs" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand=" SELECT Null [JOB_ID], '---' [JOB]
UNION
SELECT distinct [JOB_ID],[JOB] FROM [TNA].[vu_Position] where [JOB_ID] is not null and [JOB] is not null order by 2"></asp:SqlDataSource>
但我想用linq查询做这个,我尝试了所有的东西,但没有,所以请任何帮助..
答案 0 :(得分:1)
将此类和数据作为数据库的实际架构/数据的模型:
class vu_Position
{
public int? JOB_ID { get; set; }
public string JOB { get; set; }
}
List<vu_Position> Positions = new List<vu_Position>
{
new vu_Position { JOB_ID = null, JOB = "A"},
new vu_Position { JOB_ID = 1, JOB = "B"},
new vu_Position { JOB_ID = 2, JOB = "C"},
new vu_Position { JOB_ID = 3, JOB = null}
};
这是模仿SelectCommand
的{{1}}的linq查询版本:
SqlDataSource
<强>输出:强>
答案 1 :(得分:-1)
List<string> list = new List<string> {"1.5","2.5","3.1","4.2","" };
var a = (
from aa in list
select string.IsNullOrEmpty( aa) ? null : aa
);
希望它有所帮助,如果您需要更多帮助来创建列表项,请问我。