Click here to Skip to main content
11,643,493 members (75,928 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
I want slove this problum ???????


ERROR Message

String was not recognized as a valid TimeSpan.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: String was not recognized as a valid TimeSpan.

Source Error:


Line 178: dropdowncourier.SelectedItem.Text= phoneGridView.SelectedRow.Cells[2].Text;
Line 179: dropdowngetphone.SelectedItem.Text = phoneGridView.SelectedRow.Cells[3].Text;
Line 180: TimeSpan PKTime = TimeSpan.Parse(phoneGridView.SelectedRow.Cells[4].Text);
Line 181: int hours = PKTime.Hours;
Line 182: int Minutes = PKTime.Minutes;


MY CODE

 dropdowncourier.SelectedItem.Text= phoneGridView.SelectedRow.Cells[2].Text;
           dropdowngetphone.SelectedItem.Text = phoneGridView.SelectedRow.Cells[3].Text;
           TimeSpan PKTime = TimeSpan.Parse(phoneGridView.SelectedRow.Cells[4].Text);
                    int hours = PKTime.Hours;
                    int Minutes = PKTime.Minutes;
                    TimeSelector1.SetTime(hours, Minutes, TimeSelector1.AmPm);
   
          
txtremarks .Text = phoneGridView.SelectedRow.Cells[6].Text;
Posted 12-Nov-12 22:38pm
Hasiya396
Edited 12-Nov-12 22:43pm
CPallini348K
v2
Comments
Hasiya at 13-Nov-12 4:51am
   
I Need a quick help??????
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It is simply saying that the contents of phoneGridView.SelectedRow.Cells[4].Text are not recognisable as a valie TimeSpan in string form. We can't fix that: it's your data that is the problem!

Have a look at the cell content, and at the Parse method description / example : http://msdn.microsoft.com/en-us/library/se73z7b9.aspx[^] - I don't know what your data looks like, so we can't correct your problem.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please Try this,

var dt = new DateTime(2010, 06, 26); // time is zero by default
               string currTime = "19:04:06";//dateTimePicker1.Value.TimeOfDay.ToString();//19:04:06
               var tm = TimeSpan.Parse(currTime);
               var fullDt = dt + tm;
  Permalink  
Comments
CHill60 at 11-Jul-14 9:38am
   
You're a bit late ...over 19 months late

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

  Print Answers RSS
0 OriginalGriff 570
1 jyo.net 484
2 DamithSL 318
3 Afzaal Ahmad Zeeshan 253
4 CPallini 222
0 OriginalGriff 795
1 DamithSL 611
2 Mika Wendelius 494
3 jyo.net 484
4 Afzaal Ahmad Zeeshan 404


Advertise | Privacy | Mobile
Web04 | 2.8.150731.1 | Last Updated 11 Jul 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100