Click here to Skip to main content
12,749,754 members (33,713 online)
Rate this:
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;


 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 23:38pm
Updated 12-Nov-12 23:43pm
Hasiya 13-Nov-12 4:51am
I Need a quick help??????
Rate this: bad
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 :[^] - I don't know what your data looks like, so we can't correct your problem.
Rate this: bad
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;
CHill60 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 11 Jul 2014
Copyright © CodeProject, 1999-2017
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