FilterExpression - AccessDataSource

Discussion in 'ASP .Net' started by mosscliffe, May 30, 2006.

  1. mosscliffe

    mosscliffe Guest

    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.
     
    mosscliffe, May 30, 2006
    #1
    1. Advertising

  2. mosscliffe

    mosscliffe Guest

    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,
     
    mosscliffe, May 30, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RA

    FilterExpression for table

    RA, Nov 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    414
  2. Replies:
    1
    Views:
    7,447
    Markus
    Aug 25, 2005
  3. Henry Habermacher [MVP Access]

    GridView - Changing FilterExpression of SQLDataSource and Paging

    Henry Habermacher [MVP Access], Jan 20, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    11,031
    kmarchiony
    Jul 31, 2007
  4. DummyDumb
    Replies:
    2
    Views:
    5,457
    DummyDumb
    Feb 13, 2006
  5. John
    Replies:
    2
    Views:
    2,992
Loading...

Share This Page