在下拉列表中选择时区 [英] select timezone in dropdown
本文介绍了在下拉列表中选择时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello All,
我有一个asp.net下拉列表,我将所有时区绑定到它。
ddlTimeZone.DataSource = TimeZoneInfo.GetSystemTimeZones(); // 下拉列表中的绑定时区列表
ddlTimeZone。 DataValueField = Id;
ddlTimeZone.DataTextField = DisplayName;
ddlTimeZone.DataBind();
我想要的是当来自澳大利亚的用户访问我的页面时,我希望默认情况下在下拉列表中选择他的时区如果用户来自加拿大,则应选择他的时区。
我感谢任何帮助,建议,代码,链接..
提前谢谢
解决方案
我是通过Google发现的:
< a href =http://pellepim.bitbucket.org/jstz/>使用JavaScript自动检测时区 [ ^ ]
jsTimezoneDetect [ ^ ]
从浏览器获取客户时区 [ ^ ]
使用JavaScript自动检测时区 [ ^ ]
请注意,这不是C#问题,因为您需要在客户端检测时区。这意味着您可能需要使用Javascript来完成这项工作。
请参阅:使用JavaScript自动检测时区 [ ^ ]
或者看看这个< a href =http://www.w3schools.com/jsref/jsref_gettimezoneoffset.asp> W3Schools'教程 [ ^ ]
您可以将值添加到DropDownList中匹配JS给出的结果然后在JS中自动选择正确的项目。
干杯,
江户时代
Hello All,
I have a asp.net dropdown and I am binding all timezones to it.
ddlTimeZone.DataSource = TimeZoneInfo.GetSystemTimeZones();//binding time zone list in drop down list
ddlTimeZone.DataValueField = "Id";
ddlTimeZone.DataTextField = "DisplayName";
ddlTimeZone.DataBind();
What I want is when a user from Australia visit my page, I want to by default select his timezone in dropdown and if user is from canada, his timezone should be selected.
I appreciate any help, suggestion, code, link..
Thanks in advance
解决方案
I found this via Google:
Automatic Timezone Detection Using JavaScript[^]
jsTimezoneDetect[^]
get client time zone from browser[^]
Auto detect a time zone with JavaScript[^]
Note that this is not a C# question since you need to detect the timezone on the client side. This means that you probably need to use Javascript to do the job.
See: Auto detect a time zone with JavaScript[^]
Or have a look at this W3Schools' tutorial[^]
You can add values to the DropDownList to match the result given by the JS and then in JS autoselect the right item.
Cheers,
Edo
这篇关于在下拉列表中选择时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文