如何解决这个问题字符串未被识别为有效的DateTime“ [英] how to fix this " String was not recognized as a valid DateTime"

查看:115
本文介绍了如何解决这个问题字符串未被识别为有效的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;
              
         }

推荐答案

使用此:https://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx [ ^ ]



问候..
Use this : https://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx[^]

Regards..


您也可以尝试 DateTime.TryParse [ ^ ]。
You can also try DateTime.TryParse[^].


你应该使用如下:



You should use as below:

CultureInfo culture = new CultureInfo("en-US");
DateTime myDate = Convert.ToDateTime(Selectedvalue["date"].Text.ToString(),culture );
RadDatePicker_Date.SelectedDate = myDate;





希望这个帮助!



Hope this help !


这篇关于如何解决这个问题字符串未被识别为有效的DateTime“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆