Asp.net 日历在页面加载事件中选择当前星期

发布于 2024-09-08 20:52:20 字数 526 浏览 3 评论 0原文

在 Page_Load 事件中,我希望在日历上选择当前的一周,而不仅仅是当前的一天。这怎么能做到呢?

<asp:Calendar 
ID="Calendar1" 
runat="server" 
ondayrender="Calendar1_DayRender"   
SelectionMode="DayWeek" 
onselectionchanged="Calendar1_SelectionChanged">
</asp:Calendar>


        protected void Page_Load(object sender, EventArgs e)
    {

       Calendar1.SelectedDate = System.DateTime.Today;

    }

    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        e.Day.IsSelectable = false;
    }

In the Page_Load event I would like to have the current week selected on the calendar instead of just the current day. How can this be done?

<asp:Calendar 
ID="Calendar1" 
runat="server" 
ondayrender="Calendar1_DayRender"   
SelectionMode="DayWeek" 
onselectionchanged="Calendar1_SelectionChanged">
</asp:Calendar>


        protected void Page_Load(object sender, EventArgs e)
    {

       Calendar1.SelectedDate = System.DateTime.Today;

    }

    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        e.Day.IsSelectable = false;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人 2024-09-15 20:52:20

尝试一下:

Calendar1.SelectionMode = CalendarSelectionMode.DayWeek;  
ArrayList selectedDates = new ArrayList();  
DateTime today = DateTime.Now;    
DateTime firstDay = today.AddDays(-(double)(today.DayOfWeek));    
for (int loop = 0; loop < 7; loop++)    
    Calendar1.SelectedDates.Add(firstDay.AddDays(loop));   

Give this a try:

Calendar1.SelectionMode = CalendarSelectionMode.DayWeek;  
ArrayList selectedDates = new ArrayList();  
DateTime today = DateTime.Now;    
DateTime firstDay = today.AddDays(-(double)(today.DayOfWeek));    
for (int loop = 0; loop < 7; loop++)    
    Calendar1.SelectedDates.Add(firstDay.AddDays(loop));   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文