[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
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.
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
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!