C# - ASP.NET - 日历控件 - 指定的强制转换无效
我有一个网格视图,我可以在其中跟踪截止日期。我这里有 2 个约会。预期日期(截止日期应该完成的日期)和实际日期(截止日期完成的日期)。现在,在我的数据库中,所有预期日期都有值,因为它们应该在每个月的同一日期完成。但实际日期是空白的。
由于空值,这给了我以下错误:异常详细信息:System.InvalidCastException:指定的强制转换无效。 现在我在互联网上查找时发现了一些东西,那就是调用一个辅助方法(请参阅 selectedDate 属性 - 我将 selectedDate的
相同值复制到 VisibleDate 中,因为否则我遇到了相同的错误)但这给我带来了另一个错误是我无法获取新选择的值!
<asp:TemplateField HeaderText="Actual Date" SortExpression="Actual_Date">
<EditItemTemplate>
<asp:Calendar ID="Calendar2" runat="server" VisibleDate='<%# Bind("Actual_Date") %>' SelectedDate='<%# FixNullDate(Eval("Actual_Date")) %>'></asp:Calendar>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%# Bind("Actual_Date", "{0:d}") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
这是我的模板字段中的实际日期代码
请帮忙,我有点迷路了:p
I have a gridview where I keep track of deadlines. I have 2 dates herefor. A expected date (date where the deadline is supposed to be completed) and an actual date (date where the deadline was completed). Now in my DB all the expected dates have values because they are meant to finish at around the same date each month. However the actual date is blank.
This gives me following error due to the null-values: Exception Details: System.InvalidCastException: Specified cast is not valid.
Now I found something while looking on the Internet and that is to call a helper method (see the selectedDate property - I copied to same value of selectedDate into VisibleDate, because else I had the same error) However this presents me with another error which is that I can't get the newly selected value!
<asp:TemplateField HeaderText="Actual Date" SortExpression="Actual_Date">
<EditItemTemplate>
<asp:Calendar ID="Calendar2" runat="server" VisibleDate='<%# Bind("Actual_Date") %>' SelectedDate='<%# FixNullDate(Eval("Actual_Date")) %>'></asp:Calendar>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%# Bind("Actual_Date", "{0:d}") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
Here is my code of from my templatefield for the actual date
Please help, I'm kinda lost :p
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要检查是否为空:
You need to check for null: