<TextBox Text='<%DataBinder.Eval(Container.DataItem,"dt","{0:yyyy-MM-dd}")%>'详细可以看SDK文档的格式化概述.
`

解决方案 »

  1.   

    ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemWindowsFormsBindingMembersTopic.htm
      

  2.   

    textbox绑定到一日期字段,我不想在数据改变事件用format函数.
      

  3.   

    //我们要格式化日期,所以处理 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);
                }
            }