这是我使用 ajax 工具脚本在日历扩展器上所做的代码。我想计算天数,但它给出了以下异常
无法将“AjaxControlToolkit.CalendarExtender”类型的对象转换为“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>