我在aspx页面中使用此EntityDataSource从我的数据库中检索一些数据:
<asp:EntityDataSource ID="mydatasource" runat="server"
ConnectionString="name=myconnectionstring"
DefaultContainerName="mydefaultcontainer"
EnableFlattening="False"
EntitySetName="Tasks"
Select="it.[ID], (it.ID + ' - ' + ISNULL(it.Name, ' ')) as [FullTaskName]" //Second argument of ISNULL is a whitespace.
Where="it.Project = @projectID" >
<WhereParameters>
<asp:ControlParameter ControlID="tbProject" Name="projectID" PropertyName="Text" Type="String" />
</WhereParameters>
</asp:EntityDataSource>
如您所见,我选择2个字段(ID +名称)的组合作为单个字段,因此我可以在下拉列表中使用它。
在Task表中,字段Name可以为null,在这种情况下,整个FullTaskName变为null(或空字符串,我不确定)。
ID Name
0 Name0
1 NULL
2 Name2
有了这些数据,我的预期输出将是这样的:
0 - Name0
1 -
2 - Name2
但我得到了这个:
0 - Name0
2 - Name2