Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoSelect/AutoComplete Listbox

Status
Not open for further replies.

AppzDev

MIS
Oct 9, 2002
57
US
I have a listbox that get's populated from a database when a user clicks an employers name from an A-Z list. So, if the user clicks "A" the listbox get's populated with all employers that begin with "A". That works well. The problem is, there are quite a few "A's"...

What i want to do is make is to the user could type "ARN" and be brought to the Employer beginning with ARN so that person could then select them and move on...

Is there an easy way to do this? I have seen quite a few examples on the web but nothing specific to a listbox that would work in the scenario above.

I've seen this a dozen times on the web on various sites, so i assume it *can* be done...i just don't know how.

If i were to search more on the web, would i be searching for autocompleting listboxes, autoselecting listboxes, etc...

Any help is appreciated.

dc~

 
Do you want to populate the dropdownlist only with employers who's name begins with ARN? If so, all you have to do is use something like this:

Let's assume you are using oledb.

string strSQL = "SELECT EmployerID, EmployerName FROM tblEmployers WHERE EmployerName LIKE 'Arn*';";
using (OleDbConnection myConn = new OleDbConnection(strConnect))
{
myConn.Open();
OleDbCommand myCmd = new OleDbCommand(strSQL, myConn);
OleDbDataReader myRdr = myCmd.ExecuteReader();
ddlEmployers.DataSource = myRdr;
ddlEmployers.DataBind();
}
 
Thanks for the reply, but that's not what i'm looking to do. I have a an alphabet list of A-Z that if the user clicks "A" the listbox populates with all employers beginning with "A's" etc. Once the listbox is populated, i want to have the ability to begin typing in the name of an Employer and have the listbox automatically go there. Much like windows directories work...i open a directory, start typing "aut" and it brings me to the file that may begin with "aut" like "autoexec.bat". I am thinking i may have to do this in a textbox or use some fancy Java, but i wanted to kind of keep it simple...

Thanks for the reply however, i appreciate it.

dc~
 
Ok, now I know what you mean. I'd imagine someone has written a combo box control (as it's called in access). I was actually thinking of writing one myself since I'm migrating a database from access to mysql/asp.net. Everyone is used to combo boxes here.

If I find one or write one in the next couple of days I'll post it here.

I have a few ideas in my mind of how to go about this but they're somewhat lacking in beauty. I figure these are the requirements:

The "zooming" as the user enters an Employer would have to be done clientside.

There isn't a native combo box for html like in access. This means the only place a user could type would be in a textbox.

The data must be read from a database server side. That means a gap must be bridged between serverside and client side.

To bridge that gap, use an html control with a runat="server" attribute. You can then use asp.net to populate that. I'm thinking a listbox would be best.

Stick a regular old html input over the listbox. You could then use Javascript to scroll the listbox as the user enters text into the input.

It's a rough outline but I think, short of writing my own control, it's what I'd do.
 
Exactly! I did find one javascript control that did exactly what you stated, with the exception that is worked great in the demo, but i have yet to get it working. The example showed a listbox that wasn't populated from a database. I'd be interested in seeing what you come up with! Someday, oh *someday* i'll be able to write my own controls...

Thanks for the help!

dc~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top