[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 925
  • Last Modified:

asp where parameter for linq query

Here is my scenario.  I have an aspx webpage that has a dropdown in the form.  I am populating the dropdown with a view that is in my dataclasses file.  This view is just a list of years, but for the particular form I am using i need to filter the results of that view.  From the dropdown i have configured a linqdatasource.  in that wizard i selected to add some parameters to the where clause.  this works as expected when specifing year less than 2000 and greater than 1955; however, what i need to do is include all years less than current year - 9 and greater than current year - 50.  

what i think i should be able to do is something similar to select year(getdate())-9 as the default value; however, when doing so i get an error "Input string was not in a correct format"

please advise.  
<asp:DropDownList ID="BirthYear" runat="server" AppendDataBoundItems="True" 
        Width="180px" DataSourceID="LinqDataSource_DropDown_BirthYear" DataTextField="intYear" 
            <asp:ListItem Selected="True" Value="0">Choose One</asp:ListItem>
        <asp:LinqDataSource ID="LinqDataSource_DropDown_BirthYear" runat="server" 
        Select="new (intYear)" TableName="viewDropDown_Years" 
        Where="intYear &lt; @intYear &amp;&amp; intYear &gt; @intYear1">
                <asp:Parameter DefaultValue="2000" Name="intYear" Type="Int32" />
                <asp:Parameter DefaultValue="1955" Name="intYear1" Type="Int32" />

Open in new window

1 Solution
rugby148Author Commented:
I found a solution.  i did not need to use the parameter.  I could just put what i needed in the where property of the linkdatasource.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now