Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:15:31+00:00 2026-06-02T14:15:31+00:00

I have these 4 checkboxes, which constitute the string variables saljes, kopes, bytes, erbjudes.

  • 0

I have these 4 checkboxes, which constitute the string variables saljes, kopes, bytes, erbjudes. When they are checked they get the value “on”.

From this I put together a string variable (p) that contains all the numbers I want to include in the LINQ-statement.
Let say if all the checkboxes are checked, i would get a string that is “1234”, and if only checkbox 2 and 4 are checked, it would result in “24”.

In my database I have a field called “Type” which is of type int. I want to tell the database to include all the rows that have a “Type” value that can be found in the string p.

Something like this (of course my code doesn’t work, therefore I need you guys):

        var searchResult = from s in db.Ads select s;
        string p = "1";

        if (saljes != "on")
            p = p.Replace("1", "");
        if (kopes == "on")
            p += "2";
        if (bytes == "on")
            p += "3";
        if (erbjudes == "on")
            p += "4";

        searchResult = searchResult.Where(s => p.Contains(s => s.Type.ToString());

What I kinda need to do is a reversed Contains(), but how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:15:33+00:00Added an answer on June 2, 2026 at 2:15 pm

    Contains() already is a ‘reversed IN’, as described here:

    int[] productList = new int[] { 1, 2, 3, 4 };
    
    var myProducts = from p in db.Products
                     where productList.Contains(p.ProductID)
                    select p;
    

    So simply fill a List:

    var list = new List<int>();
    
    if (saljes == "on")
        list.Add(1);
    if (kopes == "on")
        list.Add(2);
    if (bytes == "on")
        list.Add(3);
    if (erbjudes == "on")
        list.Add(4);
    
    var searchResult = db.Ads.Where(s => list.Contains(s.Type));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these 3 if statements which depending on the value in the variable
I'm currently dynamically building an asp:table which contains checkboxes these checkboxes have a CheckChanged
Hi There I need to get the names and values of checkboxes that have
I have these two lines in my GET action method: var model = new
I have a GUI which has a couple of checkboxes that control special modes
I have 2 checkboxes in a form and onclick of these, some php code
I have some checkboxes that act as search filters. These search filters trigger an
I have about 9 checkboxes in which allows you to pick what items are
I have these awkward checkboxes and unfortunately I cannot rename them the same due
I have an ASP.NET MVC view which contains checkboxes for user-defined categories. <td><% foreach

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.