ASP FilterExpression issue with using an IN statement

Anthony_B
Anthony_B used Ask the Experts™
on
I am trying to filter a listing by state using a drop down list of time zones.  I have a database with

Eastern	('ME', 'VT', 'NH', 'MA', 'RI', 'CT', 'NY', 'PA', 'NJ', 'DE', 'MD', 'VA', 'SC', 'GA', 'FL', 'OH', 'WV', 'IN', 'KY')
Central	('TN', 'AL', 'MS', 'LA', 'AR', 'MO', 'IA', 'MN', 'ND', 'SD', 'NE', 'KS', 'OK', 'TX')
Mountain	('NM', 'CO', 'WY', 'MT', 'ID', 'UT', 'AZ')
Pacific	('NV', 'CA', 'OR', 'WA')

Open in new window


and a dropdownlist with the first column as the name and the second as the value.  I have another database that has a huge list of names, addresses and phone numbers, and I want to be able to control what is shown in this other drop down list by the time zone.  Below is my code for the second drop down box.

<asp:SqlDataSource ID="SqlJub" runat="server" 
        ConnectionString="<%$ ConnectionStrings:JubConnectionString %>" 
        SelectCommand="SELECT [Company], [id], [State] FROM [Contacts] WHERE (([call1] IS NULL) AND ([emailed] IS NULL)) ORDER BY [Company]"
        FilterExpression="State in '{0}%'" >
        <FilterParameters>
        <asp:ControlParameter Name="State"  ControlID="DropDownList2" />
        </FilterParameters>

    </asp:SqlDataSource>

Open in new window


Whenever I try to run the above in my web page, it gives me a message "Syntax error: The items following the IN keyword must be separated by commas and be enclosed in parentheses"

Any and all assistance would be appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try the following:

FilterExpression="State IN ('{0}%')"

I hope this helps.
Oh by the way, if you wrap the placeholder in single quotes, it will translate everything into string.  I am assuming that you are passing a comma-delimited long string based on your data above.

Try the following as well:

FilterExpression="State IN ({0})"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial