我需要创建瑞典日期使用"yyyy-MM-dd“格式的MaskedEditExtender。
我有下面的代码。CalendarExtender不适用于当前的MaskedEditExtender。此外,验证也不能正常工作。
<asp:TextBox ID="txtFSFV"
MaxLength="100"
style="width:70px"
runat="server" />
<asp:HyperLink ID="hplGetCalendar"
NavigateUrl="javascript:void(null)"
runat="server">
<img src="~/images/calendar.png" runat="server" />
</asp:HyperLink>
<ajax:CalendarExtender ID="calFSFV"
Format="yyyy-MM-dd"
Animated="false"
PopupButtonID="hplGetCalendar"
TargetControlID="txtFSFV"
runat="server" />
<ajax:MaskedEditExtender
ID="maskedFSFV"
TargetControlID="txtFSFV"
Mask="9999-99-99"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Date"
Century="2000"
CultureName="sv-SE"
UserDateFormat="YearMonthDay"
InputDirection="LeftToRight"
runat="server"/>
<ajax:MaskedEditValidator ID="MaskedEditValidator1"
runat="server"
ControlExtender="maskedFSFV"
ControlToValidate="txtFSFV"
InvalidValueMessage="Date is invalid"
IsValidEmpty="True" />谁能告诉我怎样才能为sv-SE文化创建一个掩码("yyyy-MM-dd")?
发布于 2014-02-24 03:30:33
在日历格式属性上使用yyyy/MM/dd,删除屏蔽扩展程序中的区域性,并在页面加载时使用设置区域性
system.threading.thread.currentthread.currentculture =
system.globalization.cultureinfo.invariantculture希望能有所帮助。
发布于 2013-11-09 17:59:50
当我在后台代码中设置掩码时(txtFSFV.Mask = "9999/99/99";)。因此问题似乎总是与日期分隔符("/")有关,并且CultureInfo "sv-SE“设置为"yyyy-MM-dd”。
发布于 2016-03-09 18:17:59
我花了几个小时试图改变我的网格视图上的日期格式,最后我做了以下事情,创建新的数据集,从现有的数据集(已经有数据)克隆它,然后在新创建的数据集上格式化我的日期字段。还要记住使用Global.asax文件设置正确的区域性(请参阅代码)。希望这能有所帮助
DataSet ds = new DataSet();
try
{
ds = new DataSet();
if (filterRateDiary.LoadAll())
{
DataView dv = filterRateDiary.DefaultView;
DataTable dt = dv.Table;
ds.Tables.Add(dt);
DataSet ds2 = ds.Clone();
ds2.Tables[0].Columns["ExpiryDate"].DataType = Type.GetType("System.DateTime");
ds2.Tables[0].Columns["EffectiveDate"].DataType = Type.GetType("System.DateTime");
foreach (DataRow row in ds.Tables[0].Rows)
{
ds2.Tables[0].ImportRow(row);
}
return ds2;
}然后在global.asax文件中添加以下代码
protected void Application_BeginRequest(object sender, EventArgs e)
{
CultureInfo newCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
newCulture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
newCulture.DateTimeFormat.LongDatePattern = "yyyy-MM-dd HH:mm:ss.fff";
newCulture.DateTimeFormat.DateSeparator = "-";
Thread.CurrentThread.CurrentCulture = newCulture;
}希望这能有所帮助
https://stackoverflow.com/questions/6695755
复制相似问题