如果 dataitem 为 Null
我想显示 0
<asp:Label ID="Label18" Text='<%# Eval("item") %>' runat="server"></asp:Label>
我怎样才能做到这一点?
最佳答案
您还可以在页面上创建一个公共(public)方法,然后从前面的代码中调用该方法。
例如如果使用 C#:
public string ProcessMyDataItem(object myValue)
{
if (myValue == null)
{
return "0 value";
}
return myValue.ToString();
}
那么前面代码中的标签将类似于:
<asp:Label ID="Label18" Text='<%# ProcessMyDataItem(Eval("item")) %>' runat="server"></asp:Label>
抱歉,尚未测试此代码,因此不能保证“<%# ProcessMyDataItem(Eval("item")) %>
”的语法完全正确。
关于asp.net - 使用 '<%# Eval("item") %>'; 处理空值并显示 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1979806/