本文介绍了如何解决这个问题字符串未被识别为有效的DateTime“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我正在使用radgrid..i已将数据填充到..当我点击radgrid中的行时我需要这些数据相应的textboxes..everything工作正常,除了日期...我已经使用datetimepicker ... radgrid行中的日期应该在行上点击的dateimepicker中显示。
这个是我正在使用的代码,这是我得到的消息字符串未被识别为有效日期时间
谢谢
Hello,
I'm using radgrid..i have populated the data into that ..now when i click on row in radgrid i need that data in respective textboxes..everything is working fine except date...i have used datetimepicker...date in radgrid row should be displayed in dateimepicker on row click.
This is the code im using and this is the excpetion im getting " String was not recognized as a valid DateTime"
Thank you
protected void RadGrid_Operators_SelectedIndexChanged(object sender, EventArgs e)
{
GridDataItem selectedvalue = (GridDataItem)RadGrid1.SelectedItems[0];
DateTime value = DateTime.Parse(Selectedvalue["date"].Text.ToString().Trim());
RadDatePicker_Date.SelectedDate = value;
}
推荐答案
CultureInfo culture = new CultureInfo("en-US");
DateTime myDate = Convert.ToDateTime(Selectedvalue["date"].Text.ToString(),culture );
RadDatePicker_Date.SelectedDate = myDate;
希望这个帮助!
Hope this help !
这篇关于如何解决这个问题字符串未被识别为有效的DateTime“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!