Search code examples
c#asp.netsqldatasource

Using inline expression with SessionParameter fails


This works as fine in my ASP.NET page's SqlDataSource:

<asp:SessionParameter Name="FromTimestamp" SessionField="fromtime" DefaultValue="2/22/2012" />

Why does this produces error: Conversion failed when converting date and/or time from character string.

<asp:SessionParameter Name="FromTimestamp" SessionField="fromtime" DefaultValue='<%=DateTime.Now.ToShortDateString()%>' />

Solution

  • DateTime.Now.ToString("M/d/yyyy")
    

    Will get you the format you already know works.