使用'<%#的eval("项目")%GT;';处理空值,并显示反对0 [英] Using '<%# Eval("item") %>'; Handling Null Value and showing 0 against

查看:158
本文介绍了使用'<%#的eval("项目")%GT;';处理空值,并显示反对0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果DataItem的是我想说明 0

If dataitem is Null I want to show 0

<asp:Label ID="Label18" Text='<%# Eval("item") %>' runat="server"></asp:Label>

我怎样才能做到这一点?

How can I accomplish this?

推荐答案

您也可以在页面上创建一个公共方法,然后调用从code-在前面。

You can also create a public method on the page then call that from the code-in-front.

例如。如果使用C#:

public string ProcessMyDataItem(object myValue)
{
  if (myValue == null)
  {
     return "0 value";
  }

  return myValue.ToString();
}

然后在code-在前面的标签将是这样的:

Then the label in the code-in-front will be something like:

<asp:Label ID="Label18" Text='<%# ProcessMyDataItem(Eval("item")) %>' runat="server"></asp:Label>

对不起,没有测试code所以不能保证我得到的语法&LT;%#ProcessMyDataItem(EVAL(项目))%&GT; 完全正确的。

这篇关于使用'&LT;%#的eval(&QUOT;项目&QUOT;)%GT;';处理空值,并显示反对0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆