gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:29:59 25 4
gpt4 key购买 nike

嗨,在我的代码中,每当我单击日历中的日期时,该日期就会显示在屏幕的最顶部,但我希望它显示在日历下方。有人可以提供修复吗?

<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>";
}

关于C# asp.net 日历控件从顶部移动显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34125047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com