我的網站上有一些奇怪的行為。我有一個名為 UDExpiryCalendar 的 ASP 日歷,它在頁面加載時獲取其值。我從用戶的記錄中讀入 a并DateTime填充UDExpiryCalendar.VisibleDate然后UDExpiryCalendar.SelectedDateUDExpiryCalendar.DataBind();
我得到這些結果:
- 過去的日期 - 顯示正確的月份,顯示正確的年份并選擇正確的日期。
- 日期在本月 - 顯示正確的月份,顯示正確的年份,當前日期為灰色并選擇正確的日期(即使未來幾天)。
- 日期在未來 - 顯示正確的月份,顯示正確的年份,但未選擇所選日期
有任何想法嗎?
C#
var userID = Request.QueryString["ID"];
string getUserInfo = "select * from UserList where Id =" userID;
SqlCommand getUserInfocmd = new SqlCommand(getUserInfo, con);
getUserInfocmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataReader sqlDR = getUserInfocmd.ExecuteReader();
dt.Load(sqlDR);
sqlDR.Close();
DateTime oldExpiryDate = Convert.ToDateTime(dt.Rows[0][6]);
UDExpiryCalendar.VisibleDate = oldExpiryDate;
UDExpiryCalendar.SelectedDate = oldExpiryDate;
UDExpiryCalendar.DataBind();
ASP
<asp:Calendar ID="UDExpiryCalendar" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" Width="200px">
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<NextPrevStyle VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#808080" />
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<SelectorStyle BackColor="#CCCCCC" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<WeekendDayStyle BackColor="#FFFFCC" />
</asp:Calendar>
uj5u.com熱心網友回復:
我認為問題在于您的日期中有時間組件。我對此進行了測驗并且它有效(在 Page_Load 中):
Calendar1.SelectionMode = CalendarSelectionMode.Day;
Calendar1.TodaysDate = DateTime.Now.Date;
Calendar1.SelectedDates.Clear();
Calendar1.SelectedDate = DateTime.Now.AddYears(2).Date;
Calendar1.VisibleDate = DateTime.Now.AddYears(2).Date;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/522475.html
標籤:C#网日历
