基于“预订”的日渲染日历来自 MySQL 表 ASP.NET C#
我正在尝试处理结果以更改日期在 ASP.NET 页面日历上的显示方式。我希望这样,如果在特定日期进行了“预订”,那么它将在日历上显示为红色突出显示的单元格。 问题是我只能设法让它执行一次,它会突出显示一个单元格,然后不会移动到下一个“BookingDate”。
这是代码:
conn.Open();
Reader = command.ExecuteReader();
if (Reader.Read())
{
String BookingDate = Reader.GetValue(0).ToString();
String Username = Reader.GetValue(1).ToString();
String Client = Reader.GetValue(2).ToString();
Reader.Close();
conn.Close();
String[] bookingDetails = new String[3];
bookingDetails[0] = BookingDate;
bookingDetails[1] = Username;
bookingDetails[2] = Client;
DateTime BookingDateShort = Convert.ToDateTime(BookingDate);
DateTime CalanderDate = Convert.ToDateTime(e.Day.Date);
for (int i = 0; i < GetDaysinMonth(); i++)
{
if (CalanderDate.ToShortDateString().Equals(BookingDateShort.ToShortDateString()))
{
e.Cell.BackColor = System.Drawing.Color.Red;
e.Cell.ToolTip = "Username: " + Username + " | Client: " + Client + "";
}
}
}
我知道我需要执行某种循环以使其递归地遍历每个日期的处理,将其与预订日期进行比较并检查它们是否相等。然而,它只针对一个预订日期执行此操作。
有谁知道我该如何解决这个问题?
非常感谢
I am trying to process results to change how the dates are displayed on the calander of an ASP.NET page. I want it so that if a "Booking" has been made on a particular date then it will show on the calendar as a red highligthed cell.
The problem is I am only managing to get it to do this once, it highlights one cell and then doesn't move onto the next "BookingDate".
Here is the Code:
conn.Open();
Reader = command.ExecuteReader();
if (Reader.Read())
{
String BookingDate = Reader.GetValue(0).ToString();
String Username = Reader.GetValue(1).ToString();
String Client = Reader.GetValue(2).ToString();
Reader.Close();
conn.Close();
String[] bookingDetails = new String[3];
bookingDetails[0] = BookingDate;
bookingDetails[1] = Username;
bookingDetails[2] = Client;
DateTime BookingDateShort = Convert.ToDateTime(BookingDate);
DateTime CalanderDate = Convert.ToDateTime(e.Day.Date);
for (int i = 0; i < GetDaysinMonth(); i++)
{
if (CalanderDate.ToShortDateString().Equals(BookingDateShort.ToShortDateString()))
{
e.Cell.BackColor = System.Drawing.Color.Red;
e.Cell.ToolTip = "Username: " + Username + " | Client: " + Client + "";
}
}
}
I am aware that I need to do some kind of loop to make it recursively go over this processing each date, comparing it against the bookingdate and checking whether they are equal. However It only does it for one booking date.
Does anyone see how I could fix this?
Many Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您阅读时……您期待更多结果还是只期待一个结果……?所以你需要更改以将 if 读取更改为 While 循环,
以便你的 while 循环看起来像这样
When you are doing your read..are you expecting more results or just one..? is so you need to change to change your if read to a While loop
so your while loop would look something like this