ASP.NET 日历控件中的各种日历
我需要创建一个显示日历控件的 ASP.NET 页面,该控件根据下拉列表中选择的值显示特定的日历。 目前我需要显示希伯来日历和常规(公历)日历,但将来我可能需要其他日历。 当然,我无法使用 Windows 的区域设置或 web.config 中的全球化定义,因为所需的日历是在运行时设置的。 如何在 Calendar 控件中显示各种日历?
谢谢!
I need to create an ASP.NET page that displays a Calendar control which shows a specific calendar based on value selected in a drop down.
Currently I need to display HebrewCalendar and the regualr (gregorian) calendar, but in the future I'll probably need others.
Of course I can't use the Regional Settings of Windows or the globalization definition in web.config since the required calendar is set in runtime.
How can I display various calendars in a Calendar control?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
诀窍是您需要设置当前线程的文化,并且(对于某些语言环境,例如希伯来语)还需要在该文化中设置日历。
下面的独立代码示例说明了如何执行此操作。这种方法当然可能会影响其他控件的本地化文本。如果这是一个问题 — 并且您只想本地化 Calendar 控件并将其余部分保留为英语 — 那么您可以执行以下操作:
这是代码:
The trick is you'll need to set the Culture of the current thread, and (for some locales like Hebrew) also need to set the Calendar within that Culture.
The self-contained code sample below illustrates how to do this. This approach of course may affect other controls's localized text. If this is a problem-- and you only want to localize the Calendar control and leave the rest in English-- then you can do the following:
Here's the code:
如果您需要按日历进行文化定制,请查看 BaseCalendar (其中包含一个处理此场景的演示) 。更改当前线程的文化可能会在其他地方产生副作用。 BaseCalendar 允许您指定日历的区域性,而无需更改当前线程的区域性。
If you need per-calendar culture customization have a look at BaseCalendar (there's a demo included that handles this scenario). Changing the current thread's culture could have side-effects in other places. BaseCalendar allows you to specify a culture for a calendar without changing the current thread's culture.