這是我使用ajax工具在日曆擴展器上做的代碼。我想計算天,但它提供了以下異常日曆擴展日計算例外
Unable to cast object of type 'AjaxControlToolkit.CalendarExtender' to type 'System.IConvertible'.
這裏是天計算的代碼::
protected void Page_Load(object sender, EventArgs e)
{
TextBox2_CalendarExtender.StartDate = DateTime.Now;
TextBox2_CalendarExtender.EndDate = DateTime.Now.AddDays(30);
TextBox1_CalendarExtender.StartDate = DateTime.Now.AddDays(1);
TextBox1_CalendarExtender.EndDate = DateTime.Now.AddDays(30);
}
protected void Button1_Click(object sender, EventArgs e)
{
TimeSpan days = Convert.ToDateTime(TextBox1_CalendarExtender).Subtract(Convert.ToDateTime(TextBox2_CalendarExtender));
int day = Convert.ToInt32(days.TotalDays);
Label1.Text = day.ToString();
}
,這是隻有特定部分::
ASP代碼<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="TextBox2_CalendarExtender" runat="server"
TargetControlID="TextBox2" StartDate="<%#DateTime.Now %>" EndDate=" <%#DateTime.Now.AddDays(30) %>">
</asp:CalendarExtender>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="TextBox1_CalendarExtender" runat="server"
TargetControlID="TextBox1" StartDate="<%#DateTime.Now.AddDays(1) %>" EndDate="<%#DateTime.Now.AddDays(30) %>">
</asp:CalendarExtender>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
其中在本頁面的設計模式和
user2334012
@ user2334012您沒有在此發佈任何asp代碼,所以我不太瞭解您的問題。 – Harrison
我已經給了th代碼現在,我仍然得到他同樣的例外。 – user2334012