textbox绑定到一日期字段,如何格式化日期为长日期型 <TextBox Text='<%DataBinder.Eval(Container.DataItem,"dt","{0:yyyy-MM-dd}")%>'详细可以看SDK文档的格式化概述.` 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemWindowsFormsBindingMembersTopic.htm textbox绑定到一日期字段,我不想在数据改变事件用format函数. //我们要格式化日期,所以处理 DOB 文 //本框的 format 和 parse 事件 Binding dobBinding = new Binding("Text", custList, "DateOfBirth"); dobBinding.Format += new ConvertEventHandler(this.textBoxDOB_FormatDate) ; dobBinding.Parse += new ConvertEventHandler(this.textBoxDOB_ParseDate) ; textBoxDOB.DataBindings.Add(dobBinding); //以长日期格式格式化日期字段,以便在文本框中显示 private void textBoxDOB_FormatDate(object sender, ConvertEventArgs e) { //我们只处理从日期到字符串的转换 if (e.DesiredType != typeof(string)) return ; if (e.Value.GetType() != typeof(DateTime)) return ; DateTime dt = (DateTime)e.Value; e.Value = dt.ToLongDateString(); } //分析文本框内容,并将其转换回日期 private void textBoxDOB_ParseDate(object sender, ConvertEventArgs e) { //我们只处理到日期和字符串的转换 if (e.DesiredType != typeof(DateTime)) return ; if (e.Value.GetType() != typeof(string)) return ; string value = (string)e.Value; try { e.Value = DateTime.Parse(value); } catch(Exception ex) { MessageBox.Show(ex.Message); } } 保存用户登录信息 WebBrowser居然解释不了<br />这样的元素? 如何获得enum成员的属性值? 再问个进制转换的问题 如何得到所有的活动服务器名字? 邮件发送程序问题,急! 谁有关于滚动条的最简单的代码 VS2010下建立的工程,如何选择低于.NET 4.0的版本 紧急求助!关于验证后按钮失效问题! DataGrid的列标题能重绘吗? 请问哪个日期函数可以去掉日期后的时间部分? ★★★寻找亲近字符串的有趣问题!(顶者有分)★★★
//本框的 format 和 parse 事件
Binding dobBinding = new Binding("Text", custList, "DateOfBirth");
dobBinding.Format += new ConvertEventHandler(this.textBoxDOB_FormatDate) ;
dobBinding.Parse += new ConvertEventHandler(this.textBoxDOB_ParseDate) ;
textBoxDOB.DataBindings.Add(dobBinding); //以长日期格式格式化日期字段,以便在文本框中显示
private void textBoxDOB_FormatDate(object sender, ConvertEventArgs e) { //我们只处理从日期到字符串的转换
if (e.DesiredType != typeof(string)) return ;
if (e.Value.GetType() != typeof(DateTime)) return ; DateTime dt = (DateTime)e.Value;
e.Value = dt.ToLongDateString(); }
//分析文本框内容,并将其转换回日期
private void textBoxDOB_ParseDate(object sender, ConvertEventArgs e) { //我们只处理到日期和字符串的转换
if (e.DesiredType != typeof(DateTime)) return ;
if (e.Value.GetType() != typeof(string)) return ; string value = (string)e.Value; try {
e.Value = DateTime.Parse(value);
}
catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}