Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
              
         }
Posted
Updated 30-Mar-15 3:57am
v5
Comments
Afzaal Ahmad Zeeshan 31-Mar-15 2:24am    
You can fix it by providing a valid DateTime string value.

 
Share this answer
 
Comments
Member 11148509 30-Mar-15 11:11am    
i want to convert only to date not datetime
Sergey Alexandrovich Kryukov 1-Apr-15 11:56am    
Of course; this is expected behavior if you input data is incorrect. Make is consistent and enjoy.
—SA
Sergey Alexandrovich Kryukov 1-Apr-15 11:57am    
5ed.

Rohan,

Congratulations with April 1st! :-)

I would like to use the occasion to invite your (and everyone else, of course) to see my new 1 of April publication and have some fun:
Some Programming Approaches to "Neuro-Linguistic Programming".
Participation in this game in Comments and Discussions is especially encouraged.

This time, I put more effort in the work. The fun and mocking is supposed to be combined with quite serious hints, in a satical form, on how we can conduct our discussions, give and use advice, add references and use them, use critical thinking, learn and use our own brains.

Thank you.
—SA
You can also try DateTime.TryParse[^].
 
Share this answer
 
v3
Comments
Member 11148509 31-Mar-15 2:32am    
i have tried same error
Sergey Alexandrovich Kryukov 1-Apr-15 11:55am    
Of course, because he input data is invalid. You can also use TryParseExact.
—SA
You should use as below:

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


Hope this help !
 
Share this answer
 
Comments
Member 11148509 31-Mar-15 2:29am    
din't work same error
Thanh Xuan Vu 31-Mar-15 3:18am    
Pls show RadDatePicker_Date.SelectedDate value you expected ?
Member 11148509 31-Mar-15 3:22am    
it should show the time which i have given thorugh raddatetime picker ..some date...
Member 11148509 31-Mar-15 3:58am    
when i started debugging.. when i hovered my mouse on mydate i can see exact date ...but when i hover my mouse on .text its showing null..
Data recieved is not a valid date time string even if you try the above options they wont work, use a method to convert the string to supported format i.e. mm/dd/yyyy or yyyy/mm/dd
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900