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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:33:13+00:00 2026-06-13T05:33:13+00:00

I am new to c#. I’m currently working on a search function in asp.net

  • 0

I am new to c#.

I’m currently working on a search function in asp.net with c# using three DropDownLists and a submit button. Let’s say, it’s a car website.

There are 2 DropDownLists:

  1. Make (for example – Toyota, Nissan, Honda . . .)
  2. Model (for example – Prius, X-trail, Insight . . )

If user choose only the first one (for example – he/she choose ‘Toyota’ and doesn’t choose other)and click submit, it will show all Toyota cars from the database. If user choose both ‘Make’ and ‘Model’, it will narrow the search.

If user doesn’t choose all dropdownlists, how should I write sql query for that and what if user choose all.

And the items of dropdownlists are directly added from the database. I also don’t know how to set the default value text at the top of the dropdownlist.

con.Open(); 
 if (!IsPostBack) 
 { 
     cmd = new SqlCommand("SELECT DISTINCT CarMake FROM Car", con); 
     dr = cmd.ExecuteReader(); 
     while (dr.Read()) 
     { 
        DropDownList1.Items.Add(dr[0].ToString());
     } 
 }
  • 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-13T05:33:14+00:00Added an answer on June 13, 2026 at 5:33 am

    Especially when building SQL from a public webform like this you should (I would say MUST) build your queries using parameters, not string concatenation. Otherwise it is a SQL injection attack waiting to happen.

    One simple way to handle multiple filter possibilities is to use the Like operator in the base SQL command. If either make or model is not chosen, just include a wild card instead of a make or model name:

    var baseQuery = "SELECT * FROM Car " 
                    "WHERE MAKE LIKE @MakeFilter AND MODEL LIKE @ModelFilter";
    var cmd = new SqlCommand(baseQuery, con);
    cmd.Parameters.Add(new SqlParameter( 
        "@MakeFilter", (string)ddlMake.SelectedValue ?? "%"));
    cmd.Parameters.Add(new SqlParameter( 
        "@ModelFilter", (string)ddlModel.SelectedValue ?? "%"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to jquery question... Using jQuery, depending on the radio button clicked I would
new on ruby and using windows xp and rails 3, i want to send
new to c#. I'm trying to make a simple system where I can search
New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
New to SharePoint. I'm trying to upload a document to SharePoint using it's CopyIntoItems
I want use html5's new tag to play a wav file (currently only supported
new to razor, I have a label and a button <form action= method=post enctype=multipart/form-data>
New to SQL. Using oracle sql developer Version 3.1.07. Is there any way to

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.