Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的页面有问题,因为一行中的某些列值是 NULL,如果它不是 NULL,我怎样才能只显示该值?
<ItemTemplate> <tr> <td><%# Eval("some_db_column") %></td> </tr> </ItemTemplate>
尝试这个:
<%#Eval("some_db_column") ?? "" %>
?? 运算符(C# 参考)
如果这不起作用,您还可以在代码隐藏中调用一个方法:
protected string GetValue(object obj) { if (obj == null || DBNull.Value.Equals(obj)) { return String.Empty; } return obj.ToString(); }
aspx:
<%# GetValue(Eval("some_db_column")) %>