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

  • Home
  • SEARCH
  • 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 8741681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:21:35+00:00 2026-06-13T11:21:35+00:00

I have a search field that uses a Drop down list to Filter search

  • 0

I have a search field that uses a Drop down list to Filter search results by division.

I finally got it working great but now I want to make an ALL option to negate this. The drop down values are equal to an int. I am still learning so the only way I can bend my mind around this would be a if else statement in the where query. When i did that i saw a lot of red.

There are 5 options on the Drop down list. The values are 1 through 5. 5 = all. I want to basically stop searching by division or eliminate the t0.DivisionID == DDLInt &&

string DDL = DDLAddDivision.SelectedValue;
int DDLInt;
if (int.TryParse(DDL, out DDLInt))
{
    int searchID;
    if (!int.TryParse(txtSearch.Text.Trim(), out searchID))
        searchID = -1;  // set to an invalid ID


    ItemContext db = new ItemContext();
    var q = (from t0 in db.Item
             join t1 in db.Categories on t0.CategoryID equals t1.CategoryID
             join t2 in db.Divisions on t0.DivisionID equals t2.DivisionID

             where


              t0.DivisionID == DDLInt &&

                 //Contains

            (
             t0.ItemName.Contains(txtSearch.Text.Trim()) ||
             t0.Email.Contains(txtSearch.Text.Trim()) ||
             t0.Description.Contains(txtSearch.Text.Trim()) ||
             t0.Phone.Contains(txtSearch.Text.Trim()) ||
             t0.ItemID.Equals(searchID)
             )
             group t0 by new
             {
                 t0.ItemID,
                 t0.ItemName,
                 t0.Description,
                 t0.Phone,
                 t0.Email,
                 t0.DivisionID,
                 t0.CategoryID,
                 t1.CategoryName,
                 t2.DivisionName


             } into i

             select new
             {
                 i.Key.ItemID,
                 i.Key.ItemName,
                 i.Key.Description,
                 i.Key.Email,
                 i.Key.Phone,
                 i.Key.CategoryName,
                 i.Key.DivisionName,
                 i.Key.CategoryID,
                 i.Key.DivisionID

             });

    if (q.Any() == false)
    {
        ResultsLabelId.Visible = true;
    }
    else
    {
        ResultsLabelId.Visible = false;
    }

    //bind and return
    lv.DataSource = q.ToList();
    lv.DataBind();

Thank you for any and all help!

  • 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-13T11:21:36+00:00Added an answer on June 13, 2026 at 11:21 am

    How about replacing that line with:

    (DDLInt == 5 || t0.DivisionID == DDLInt) &&
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a location search field that I want to accept pretty much
I have one table view that should be filtered by values of search field
I have a form field that uses some Javascript to format user input 'price'
I have search query that has many optional parameters and then search word field
Hey guys, I have a search field that is not submitting when the enter
Hi I have a field that uses ajax to bring up product/item information <input
I have an application that uses lucene for searching. The search space are in
I've got a field type that uses the Keyword Tokenizer (whole term is a
I have an ASP.NET page that contains two div's. Both have search fields and
I currently have an advanced search page that searches a number of fields in

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.