Results 1 to 4 of 4

Thread: [RESOLVED] Inline TryParse and IIF in C#

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Resolved [RESOLVED] Inline TryParse and IIF in C#

    How do i set the label's text depending on the data field value. e.g. if it's proper datetime value then display it, otherwise display "unknown". Please notice that it's inline C# code

    Code:
    Text='<%# DateTime.TryParse(Eval("MyDate"), out DateTime.Parse("1/1/1753")) == true ? Eval("MyDate") : "unknown" %>'
    Thanks
    Last edited by selanec; Mar 18th, 2010 at 03:27 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Inline TryParse and IIF in C#

    The second argument must be a variable, so you have to have a variable declared in C# code to pass. You might be better off writing your own function that takes a string and returns either that string or "unknown", then putting a call to that into your script. That function can then use DateTime.TryParse internally.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Inline TryParse and IIF in C#

    Hey,

    selanec, is there a reason why you are choosing to do that much code inline? Why not do that work on the server side, where it belongs?

    Gary

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    592

    Re: Inline TryParse and IIF in C#

    You are right jmcilhinney. I came with the same conclusion. Thanks for the reply.
    Thank you Gary too!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width