-3

' > System.InvalidCastException: Conversion from type 'TimeSpan' to type 'String' is not valid ' > I have a gridview , i want that the column"duréeCalculée" take like this value "text='<%# (TimeSpan.Parse(Eval("heure_retour") - Eval("heure_depart"))).ToString()%>'" but when my page generate I got this problem(Conversion from type 'TimeSpan' to type 'String' is not valid) Can U help Me?

  • 3
    It seems you forgot to include a question in your question. – Biffen Mar 23 '15 at 12:04
  • yes, It's my first question in this website! my question is how to successfully make the conversion of a timespan to String . – user3636187 Mar 23 '15 at 12:09
  • 1
    Then you should read http://stackoverflow.com/tour and http://stackoverflow.com/help/how-to-ask and then come back and edit your question. – Biffen Mar 23 '15 at 12:11
  • 1
    That's not how this site works. Write a good question and you're more likely to get help. Currently your question has a horrible title and nothing but code and an error for content. Did you read those pages? I notice you've added an answer below that looks like it should really have been added to the question. You do know that you can *edit* the question? – Biffen Mar 23 '15 at 12:26
  • ok Biffen ; I appreciate your help . – user3636187 Mar 23 '15 at 12:34
  • In my codebehind i have this lines: and when I generate my page I got this problem :System.InvalidCastException: Conversion from type 'TimeSpan' to type 'String' is not valid ! – user3636187 Mar 23 '15 at 12:38
  • Please, please, *please* **edit** your question to include all relevant information. *Don't* put it in an answer, *don't* put it in a comment, *do* put it *in the question itself*. – Biffen Mar 23 '15 at 12:41
  • "my question is urgent!" is the fastest way to get ignored and downvoted – Matt Johnson-Pint Mar 26 '15 at 01:05

1 Answers1

0

I'm uncertain with this little information that anyone will be able to help you. It would seem that TimeSpan.Spare() is returning a structure of type TimeSpan. When you try to use .ToString(), your compiler isn't figuring out what to do because .ToString() isn't recognised as a conversion method for types TimeSpan.

Most likely what you need to do is get the element TimeSpan that you want and then parse it. Something along the lines of

double Element1 = TimeSpan.Element1;
char str[64];
sprintf(str,"%f",Element1);

Where Element1 is the name of the element you wish to retrieve.