5

I am very new to C#, so my question may be silly but I realy can't solve it by myself & googling. I need to check if year is leap, so:

<mso:if runat=server condition='<%# DateTime.IsLeapYear(2000)%>'>

works fine. But I need to get Year from somewhere, e.g. MS SQL:

 YEAR(getDate()) AS yarr

...

<mso:if runat=server condition='<%# DateTime.IsLeapYear(<%#Convert.ToInt32(DataBinder.Eval(Container.DataItem, "yarr"))%>)%>'>

Error:

CS1040: Preprocessor directives must appear as the first non-whitespace character on a line

But why? Don't see any space before year.

1 Answer 1

8

You used scriptlet <%# %> twice which are nested, remove one.

condition='<%# DateTime.IsLeapYear(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "yarr")))%>'
Sign up to request clarification or add additional context in comments.

3 Comments

unfortunately no, "Server tag is not well formed"
One right parenthesis was missing from my answer, test with updated code.
Tbh better way is checking year without MS SQL: <script language="C#" runat="server">int is_leap_year = DateTime.Today.Year;</script>...<mso:if runat=server condition='<%# DateTime.IsLeapYear(is_leap_year) %>'>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.