当我绑定网格日期格式更改时,我有一个带有日历控制扩展器的文本框 [英] I Have Textbox With A Calender Control Extender Inside A Grid When I Bind The Grid Date Format Changes
本文介绍了当我绑定网格日期格式更改时,我有一个带有日历控制扩展器的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的默认格式是dd / MM / yyyy
将其绑定到网格后,格式更改为MM / dd / yyyy
My default format is dd/MM/yyyy
After binding it to grid the format changes to MM/dd/yyyy
推荐答案
如果您使用的是绑定字段,请尝试此操作:
Try this,if you are using bound fields:
<%# Bind("date", "{0:dd/MM/yyyy}") %>>
或
为了使其更灵活,制作一个函数并传递你想要的格式。
Or
To make it more flexible, make a function and pass the desired format you want.
public String DateToString(DateTime date, Int32 dateFormat)
{
String result = "";
if (dateFormat == 1)
result = date.ToString("MM/dd/yyyy");
else
result = date.ToString("dd/MM/yyyy");
return result;
}
在网格视图的RowDataBound事件中,您可以传递指定的日期格式。
On Grid view's RowDataBound event you can pass specify date format.
txtDate.Text = DateToString(Convert.ToDateTime(row["Date"].ToString()), DateFormat);
希望这会有所帮助。
谢谢
Hope this will help.
Thanks
网格绑定数据来自数据库格式为MM / dd / yyyy,您可以使用存储过程中的select语句作为convert(VARCHAR(10),DateColumn,103)AS Coulumnname....还可以通过更改来更改格式103至101,102,104,105等
Grid binds the data from the database which is in the format MM/dd/yyyy , you can use the select statement in the stored procedure as "convert(VARCHAR(10), DateColumn,103) AS Coulumnname" ....Also you can change format by changing 103 to 101,102,104,105 etc
这篇关于当我绑定网格日期格式更改时,我有一个带有日历控制扩展器的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文