I am trying to create a LinqDataSource to bind to a DropDownList in an ASP.NET form. I want to show only items according to date (which is one of the fields in the database).
Basically, the elements that I want to show are those that will be executed in futures (i.e. after DateTime.Now).
I tried the following markup:
<asp:DropDownList runat="server" ID="DropDownList1"
AppendDataBoundItems="True" DataSourceID="LinqDataSource1"
DataTextField="TextField" DataValueField="ValueField">
</asp:DropDownList>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="DataContext1" TableName="Table"
Where="DateField >= @DateField">
<WhereParameters>
<asp:Parameter DefaultValue="DateTime.Now" Name="DateField"
Type="DateTime" />
</WhereParameters>
</asp:LinqDataSource>
I get an exception in the format saying "the string was not recognized as a valid DateTime" when I try to run it. However, the dates in my database seem fine, because DateTime.Parse works great on them. DateField is a datetime type in SQL.
What am I missing here?
Thanks!
source
share