C#asp.net日历控件从顶部移动显示



嗨,在我的代码中,每当我点击日历中的日期时,日期都会显示在屏幕的最顶部,但我希望它显示在日历下面。有人能提供修复吗?

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="text">
    <span>Looking to book an appointment with us? Choose your date below:</span>
    <asp:Calendar ID="myCalendar" runat="server"  OnSelectionChanged="myCalendar_SelectionChanged">
        <TodayDayStyle BackColor="Yellow" />
        <TitleStyle Font-Bold="true" BorderStyle="Groove" />
        <DayStyle ForeColor="Silver" Font-Bold="true" />                        
    </asp:Calendar>

背后的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Calender : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void myCalendar_SelectionChanged(object sender, EventArgs e)
{
    Response.Write("You selected: " + myCalendar.SelectedDate.ToLongDateString() + " Book it?");
    if (myCalendar.SelectedDate.ToShortDateString() == "12/25/2015")
        Response.Write(" <b>Christmas CLOSED!</b>");
    if (myCalendar.SelectedDate.ToShortDateString() == "1/01/2015")
        Response.Write(" <b>Happy New Years CLOSED!</b>");
}

}

您使用的是Response.Write,它将文本输出到页面的开头。

使用标签来显示您的邮件。。。

页面

<asp:Calendar runat="server" ID="myCalendar" OnSelectionChanged="myCalendar_SelectionChanged" />
<p><asp:Label runat="server" ID="lblCalendarInfo" /></p>

代码隐藏

protected void myCalendar_SelectionChanged(object sender, EventArgs e)
{
    lblCalendarInfo.Text = string.Format("You selected: {0}. Book it?", myCalendar.SelectedDate.ToLongDateString());
    if (myCalendar.SelectedDate.ToShortDateString() == "12/25/2015")
        lblCalendarInfo.Text = "<b>Christmas CLOSED!</b>";
    if (myCalendar.SelectedDate.ToShortDateString() == "1/01/2015")
        lblCalendarInfo.Text = "<b>Happy New Years CLOSED!</b>";
}

最新更新