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 1027437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:14:27+00:00 2026-05-16T12:14:27+00:00

Still really struggling with this and appear to be going round in circles. I

  • 0

Still really struggling with this and appear to be going round in circles.

I have the following code that is driving me nuts. It should populate a list of items to be used in an autocomplete text box:

public string[] GetAutoComplete(string prefixText, int count)
    {
            string memberid = HttpContext.Current.Session["MemberID"].ToString(); 
            string locationid = HttpContext.Current.Session["LocationID"].ToString();
            string inhouse = HttpContext.Current.Session["Inhouse"].ToString();
            string supplier = HttpContext.Current.Session["Supplier"].ToString();
            string groupw = HttpContext.Current.Session["Group"].ToString();
            string external = HttpContext.Current.Session["External"].ToString();

            MyEnts autocomplete = new MyEnts();

            var r = from p in autocomplete.tblAutoCompletes
                        where p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText)
                        select p.ACItem;

            if (inhouse == "Inhouse")
                r = r.Where(p => p == inhouse);

            if (supplier == "Supplier")
                r = r.Where(p => p == supplier);

            if (groupw == "Group")
                r = r.Where(p => p == groupw);

            if (external == "External")
                r = r.Where(p => p == external);

            r.OrderBy(p => p);

            return r.ToArray();

What I am trying to retrieve with the dynamic where clause along the lines of the following.

Should inhouse = “Inhouse”, then the list of items should include the word “Inhouse”. If inhouse != “Inhouse”, the word “Inhouse” should be excluded from the list.

This same logic should then be applied across the different where clauses i.e. Supplier, Group, External.

I genuinely have tried lots of different methods but I cannot for the life of me get the thing to work and it’s frustrating me somewhat.

If anyone can suggest a way of doing this, you will either get a big kiss or a big frosty beer should our paths ever cross.

  • 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-05-16T12:14:27+00:00Added an answer on May 16, 2026 at 12:14 pm

    Not exactly sure about your problem here but if you want to exclude then shouldn’t the code be something like

     if (inhouse == "Inhouse")
                    r = r.Where(p => p == inhouse);
     else
                    r = r.Where(p => p != inhouse);
    

    Oh! if you want just exclusion then the code should be something like

    if (inhouse != "Inhouse")
                        r = r.Where(p => p != inhouse);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really struggling with this piece of code. What I'm trying to achieve: I
I have been struggling with this for a while and could really use some
I'm a complete noob in java. I still really don't know how to code.
After ages of programming in php this question seems really weird still to me.
Really like objectify, although still struggling with what is the best way to structure
I fear this has been beaten to death, but I'm still struggling with the
I'm really new to Ruby (first day!) and I'm struggling with this here. I'm
I am really struggling with this one. Below is an image of a layout
I am really struggling with using the SqlLite in my App; I have set
I'm really struggling with the following pinvoke call. I've tried numerous different ways of

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.