FilterExpression - AccessDataSource

M

mosscliffe

I am trying to filter an accessdatsource by adding a FilterExpression

If I have Field = 2 It works fine
If I have Field IN (1,5,7) it works fine

So now I want it to reference a dropdownlist

so I try Field = ddlCats.SelectedValue - Fails Miserably

So I read further and try

Field='@FieldID'
and then in FilterParameters I have FieldID pointing at
ddlCats.SelectedValue

SelectedValue and the field being tested are INTS

SourceCode Generated
<asp:AccessDataSource ID="accGetMatched" runat="server"
DataFile="~/AppData/lists.mdb"
SelectCommand="SELECT [ListID], [CatID], [Category],
[Title], [Details] FROM [PublicLists] WHERE (([Title] LIKE '%' + ? +
'%') OR ([Details] LIKE '%' + ? + '%'))" FilterExpression="CatID =
'@CatID'">
<SelectParameters>
<asp:ControlParameter ControlID="tbxLookup"
Name="Title" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="tbxLookup"
Name="Details" PropertyName="Text" Type="String" />
</SelectParameters>
<FilterParameters>
<asp:ControlParameter ControlID="ddlCats" Name="CatID"
PropertyName="SelectedValue" />
</FilterParameters>


</asp:AccessDataSource>
-------------------------------------------------------------------------------------------------

I get the following error message:
Cannot perform '=' operation on System.Int32 and System.String

The Like tests based on the textboxes all work it is only when I try to
filter on the value of the dropdownlist do I get the error.

I may be completely wrong in how I am attempting to do this filter, but
I will always do the LIKE Filtering, but only occasionally the
FilterEpression. When I get it working I will attempt to fill the
properties programmatically.

If I do not have the quotes around 'FieldID' it gives the error: Can't
find Column FieldID

Any pointers or example syntax, would be gratefully received.
 
M

mosscliffe

On further research it may be because SelectedValue is a string, but
when I try my filter as

<asp:AccessDataSource ID="accGetMatched" runat="server"
DataFile="~/AppData/lists.mdb"
SelectCommand="SELECT [ListID], [CatID], [Category],
[Title], [Details] FROM [PublicLists] WHERE (([Title] LIKE '%' + ? +
'%') OR ([Details] LIKE '%' + ? + '%'))
order by category,
title" FilterExpression="CatID ='@CatID'">
<SelectParameters>
<asp:ControlParameter ControlID="tbxLookup"
Name="Title" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="tbxLookup"
Name="Details" PropertyName="Text" Type="String" />
</SelectParameters>
<FilterParameters>
<asp:parameter
DefaultValue="Int32.Parse(ddlCats.SelectedValue)" Name="CatID" />
</FilterParameters>

Cannot perform '=' operation on System.Int32 and System.String

Please help, I am wasting so much time,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top