关于RowDataBound 代码的出错的问题,请求解决!

kof821117 2009-03-11 07:36:08
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime bookingdate = DataBinder.Eval(e.Row.DataItem, "bookingdate");
if (bookingdate < DateTime.Now.Day())
e.Row.BackColor = Color.Yellow;
}


Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0266: Cannot implicitly convert type 'object' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)

Source Error:



Line 20: if (e.Row.RowType == DataControlRowType.DataRow)
Line 21: {
Line 22: [color=#FF0000]DateTime bookingdate = DataBinder.Eval(e.Row.DataItem, "bookingdate");
Line 23: if (bookingdate < DateTime.Now.Day())
Line 24: e.Row.BackColor = Color.Yellow;
[/color]
...全文
83 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
kof821117 2009-03-11
  • 打赏
  • 举报
回复
这次对了~~

是datatime.today


谢谢各位热心的对我这个超级笨的菜鸟帮助了~~


真的谢谢各位了!!!
insus 2009-03-11
  • 打赏
  • 举报
回复
试试:


if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Data.DataRowView drv = (System.Data.DataRowView)e.Row.DataItem;

DateTime bookingdate = Convert.ToDateTime(drv["bookingdate"]); // DataBinder.Eval(e.Row.DataItem, "bookingdate");
if (bookingdate < DateTime.Now.Date) // DateTime.Now.Day())
e.Row.BackColor = Color.Yellow;
}
kof821117 2009-03-11
  • 打赏
  • 举报
回复
这次行了。不过说我的 if (bookingdate < DateTime.Now.Day()) 有问题~~·
我晕啊~~~

DateTime.Now.Day()) 就是当前日期,,因为怎么表示呢

谢谢你了
liuyeede 2009-03-11
  • 打赏
  • 举报
回复
DateTime bookingdate = Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "bookingdate"));
kof821117 2009-03-11
  • 打赏
  • 举报
回复
还是不行~说overload了~~~

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for 'System.DateTime.Parse(string)' has some invalid arguments
kof821117 2009-03-11
  • 打赏
  • 举报
回复
应该怎么解决

他说我的 DateTime bookingdate = DataBinder.Eval(e.Row.DataItem, "bookingdate"); 有问题~~我找不出~ 怎么理解呢
liuyeede 2009-03-11
  • 打赏
  • 举报
回复
类型不能实现隐式转换,写成下面的试一下:
DateTime bookingdate = DateTime.Parse(DataBinder.Eval(e.Row.DataItem, "bookingdate"));

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧