asp.net c#:布尔值为空时的eval函数 [英] asp.net c# : eval function when boolean value is empty
本文介绍了asp.net c#:布尔值为空时的eval函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道如何检查一个为空的布尔值(没有数据行的表).
我的代码:
I need to know how to check a Boolean value that is empty ( table with no data row).
my code:
<itemtemplate>
<asp:Image ImageUrl=<%# GetCheckMark((bool)Eval("CanInsert")) %> ID="ImgCanInsert" runat="server" />
</itemtemplate>
当表为空时,此函数引发错误.在后面的代码中,我检查真假,并更改图片网址.因此,我如何在eval()之前检查它是否为空,我已经尝试过但没有办法:
when table is empty this function raise error. In code behind I check for true and false and change image url. So how can I check before eval() to know if it is empty I have tried this but no way:
ImageUrl=<%# Eval("CanSee") == null?"0": GetCheckMark(Eval("CanInsert")) %>
请帮帮我.
Please help me.
推荐答案
我已经用这种方式更改了它,现在它正在运行:
I have change it in this way and now it is running:
<itemtemplate>
<asp:image imageurl="<%# String.IsNullOrEmpty(Eval("CanInsert").ToString()) ? "-" : GetCheckMark(Eval("CanInsert").ToString())%>" id="ImgCanInsert" runat="server" xmlns:asp="#unknown" />
</itemtemplate>
后面也有代码:
also code behind:
protected string GetCheckMark(string checkd)
{
return checkd == "True" ? "../../../../../ServerFile/Icons/Editor/True.png" : "../../../../../ServerFile/Icons/Editor/False.png";
}
谢谢所有
Thanks all
这篇关于asp.net c#:布尔值为空时的eval函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文