Click here to Skip to main content
15,881,776 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello,

I am currently completing a side project. The biggest ideal of it all has to do with a dynamic drop down box. I have heard and seen of the 'auto complete textbox' feature by using ajax/jquery toolkits. That is what I'm looking for, but I was wondering if there is any way of a simple way to do it? Below is what I have so far. I am connected to SQL Server database and can retrieve information based off the columns, but only one at a time. My two questions are asked below. Any tips or more feedback would be greatly appreciated!


http://i.stack.imgur.com/7X56V.png[^]


http://i.stack.imgur.com/Rj4a3.png[^]



I'm only searching by "First_Name" characters only. If I were to search for "Last_Name", "Gender" or "Age" it wouldn't work unless I deleted the First_Name column from the code and replaced it with a new column name. That is why I am asking is there any way I could include all four columns in the code above to ensure everything would be searchable?

And this is what I mean by 'dynamic'. http://kmplot.com/analysis/index.php?p=service&cancer=ovar
The link above better illustrates. You randomly start typing characters in the "Affy id/Gene symbol" textbox and receive an unlimited options of sequences to choose from. This is where I'm stuck and need to implement this type of method into my project.

My back end code:


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
 
public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=SKYNET-1000\\SQLEXPRESS;Initial Catalog=CSC_480;Integrated Security=True"); 
    
 

    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String str = "select * from People where (First_Name like '%' + @search + '%')";
        SqlCommand win7 = new SqlCommand(str, con);
        win7.Parameters.Add("@search", SqlDbType.NVarChar).Value = TextBox1.Text;
 

        con.Open();
        win7.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = win7;
        DataSet ds = new DataSet();
        da.Fill(ds, "First_Name");
        GridView2.DataSource = ds;
        GridView2.DataBind();
        con.Close();
    }
}
Posted
Updated 31-Jul-14 15:42pm
v2

1 solution

You can use OR[^] keyword to fulfill your requirement :

E.g.
SQL
select * from t_DemoDropDown where First_Name like '%' + @search + '%' OR Last_Name like '%' + @search + '%' OR Gender  like '%' + @search + '%' OR Age like '%' + @search + '%'


Good luck
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900