我有一个绑定到 SQL 结果的 ASP.NET 控件:
<asp:GridView ID="EmployeeSearchResults" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText="Status" SortExpression="Status">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# (EmployeeSearchStatus(Eval("SeparationDate"),Eval("PositionTitle"),Eval("EffectiveDate"))) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我的 EmployeeSearchStatus 函数非常基础,测试传入的值是否为 NULL,并创建一个字符串来显示:
Public Function EmployeeSearchStatus(ByVal SeparationDate As Object, ByVal PositionTitle As Object, ByVal EffectiveDate As Object) As String
Dim ReturnString As String = ""
If IsDBNull(SeparationDate) Then
ReturnString = "Currently Employed as "
Else
ReturnString = "Last Employed as "
End If
ReturnString += PositionTitle
If IsDBNull(SeparationDate) Then
ReturnString += " (effective " + EffectiveDate + ")."
Else
ReturnString += " (separated on " + SeparationDate + ")."
End If
Return ReturnString
End Function
这是处理从 SQL 返回到 ASP.NET 控件的 NULL 值的正确方法吗?有没有更好的技术?
谢谢,
罗素