检查Eval(“ VALUE”)是否为空 [英] Check if Eval("VALUE") is null

查看:237
本文介绍了检查Eval(“ VALUE”)是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#的新手,我需要转换一个值以在日期中添加分钟,但它可以为null。这是我的操作方法:

Quite new to C# I need to cast a value to add minutes to a date but it can be null. Here's how I do :

if(Eval("DUREE") != DBNull.Value)
{
    var duration = Convert.ToInt32(Eval("DUREE"));
    var date = Convert.ToDateTime(Eval("DATE"));
    var dateAsString = Convert.ToString(date.AddMinutes(duration));
    DataBinder.Eval(Container.DataItem, dateAsString, "{0:HH:mm}") 
}
else
{
    " - "
}

这是我得到的错误:


DataBinding:'System.Data.DataRowView'不包含称为''17 / 04/2014 13:30:00'的属性。

DataBinding : 'System.Data.DataRowView' doesn't comport properties called : '17/04/2014 13:30:00'.

那么,检查是否为假?还是错误在其他地方?

So, does the check is false? Or the error is elsewhere?

推荐答案

尝试在需要日期,或带有-的字符串的地方使用aspx中的代码/ p>

Try use code in aspx in place where you need the string with date or " - "

<%# Eval("DUREE") == DBNull.Value || Eval("DATE") == DBNull.Value
    ? " - "
    : Convert.ToString(Convert.ToDateTime(Eval("DATE")).AddMinutes(Convert.ToInt32(Eval("DUREE")))), "{0:HH:mm}") %>

您的代码中的问题,您在 DataBinder.Eval 传递带有日期但不包含属性名称的第二个参数字符串。

Problem in your code that you in DataBinder.Eval pass second parameter string with date but not property name.

这篇关于检查Eval(“ VALUE”)是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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