473,698 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Address book data lookup (maybe javascript)

Hi. I have the following problem - I need to build a user-control in
asp.net (an ascx) to somehow allow the users to search by first name
or last name among a big (~10.000 records) email addresses database
(SQL server table). I am thinking of allowing them to type something
in EITHER the last name, EITHER the first name textbox, and on each
text change to show in a combobox the records starting with that
letter combination.

Say for example that you have the following email addresses:

Hardy
John Doe
John Foe
John Poe
Johny Roe
Johny Zoe
Laurel
......

When you type in the FirstName textbox the string "John", the combo
box should position itself on John Doe. Hardy should still be visible
right above John Doe, if you open the combobox, but John Doe should be
selected. If you type Johny, it should position itself onto Johny Roe.
If you type Johnson, it should show the first element of the combobox,
a null string, since there is no Johnson in the list.

Similar functionality for the LastName textbox.

Finally, when you are happy with the selection in the combobox, say
"Johny Roe", you click a 'Search' button which will populate the
search form with Johny Roe's ID.

My problem is that I don't know how to best implement this. I'm
thinking of tying somehow keypresses with some server code which will
interogate the SQL server database. I'm afraid of the reaction time of
this control, though.

Question: How do I associate code with keypresses ? I can't use
Javascript for this, because I need to look up the string into SQL
tables on the server, and a textbox has only a TextChanged event.

Although I know how to write the server code, I still don't know how
to do this overall - and still I have seen something like that before,
and it worked great, and super-fast - actually I don't know if it
involved trips to the server, although I guess it did.

Do you have any advice, please ? Thank you very much !
Alex. Nitulescu

Apr 9 '07 #1
3 2413
On Apr 9, 11:07 am, "Radu" <cuca_macaii2.. .@yahoo.comwrot e:
Hi. I have the following problem - I need to build a user-control in
asp.net (an ascx) to somehow allow the users to search by first name
or last name among a big (~10.000 records) email addresses database
(SQL server table). I am thinking of allowing them to type something
in EITHER the last name, EITHER the first name textbox, and on each
text change to show in a combobox the records starting with that
letter combination.

Say for example that you have the following email addresses:

Hardy
John Doe
John Foe
John Poe
Johny Roe
Johny Zoe
Laurel
.....

When you type in the FirstName textbox the string "John", the combo
box should position itself on John Doe. Hardy should still be visible
right above John Doe, if you open the combobox, but John Doe should be
selected. If you type Johny, it should position itself onto Johny Roe.
If you type Johnson, it should show the first element of the combobox,
a null string, since there is no Johnson in the list.

Similar functionality for the LastName textbox.

Finally, when you are happy with the selection in the combobox, say
"Johny Roe", you click a 'Search' button which will populate the
search form with Johny Roe's ID.

My problem is that I don't know how to best implement this. I'm
thinking of tying somehow keypresses with some server code which will
interogate the SQL server database. I'm afraid of the reaction time of
this control, though.

Question: How do I associate code with keypresses ? I can't use
Javascript for this, because I need to look up the string into SQL
tables on the server, and a textbox has only a TextChanged event.

Although I know how to write the server code, I still don't know how
to do this overall - and still I have seen something like that before,
and it worked great, and super-fast - actually I don't know if it
involved trips to the server, although I guess it did.

Do you have any advice, please ? Thank you very much !
Alex. Nitulescu
In the TextChanged event of the text box you can perform a lookup of
the first value containing the StartsWith(txtF irsName.Text) within the
dropdownlists list of values. The first found item I'd set the
dorpdownlist's selected index value to that entry's index.

foreach(x=0; x<dropdownlist. items.count; x++)
if (dropdownlist.i tems[x].text.startswit h(txtfirstname. text))
{
dropdownlist.se lectedindex=x;
break;
}

This begs for the use of the Ajax Toolkit. You could do the lookup and
refresh the dropdownlist in the background using an asynchronous
callback by placing the controls on an Ajax update panel.

Apr 9 '07 #2
On Apr 9, 11:53 am, "wmain" <mainmeis...@gm ail.comwrote:
On Apr 9, 11:07 am, "Radu" <cuca_macaii2.. .@yahoo.comwrot e:
Hi. I have the following problem - I need to build a user-control in
asp.net (an ascx) to somehow allow the users to search by first name
or last name among a big (~10.000 records) email addresses database
(SQL server table). I am thinking of allowing them to type something
in EITHER the last name, EITHER the first name textbox, and on each
text change to show in a combobox the records starting with that
letter combination.
Say for example that you have the following email addresses:
Hardy
John Doe
John Foe
John Poe
Johny Roe
Johny Zoe
Laurel
.....
When you type in the FirstName textbox the string "John", the combo
box should position itself on John Doe. Hardy should still be visible
right above John Doe, if you open the combobox, but John Doe should be
selected. If you type Johny, it should position itself onto Johny Roe.
If you type Johnson, it should show the first element of the combobox,
a null string, since there is no Johnson in the list.
Similar functionality for the LastName textbox.
Finally, when you are happy with the selection in the combobox, say
"Johny Roe", you click a 'Search' button which will populate the
search form with Johny Roe's ID.
My problem is that I don't know how to best implement this. I'm
thinking of tying somehow keypresses with some server code which will
interogate the SQL server database. I'm afraid of the reaction time of
this control, though.
Question: How do I associate code with keypresses ? I can't use
Javascript for this, because I need to look up the string into SQL
tables on the server, and a textbox has only a TextChanged event.
Although I know how to write the server code, I still don't know how
to do this overall - and still I have seen something like that before,
and it worked great, and super-fast - actually I don't know if it
involved trips to the server, although I guess it did.
Do you have any advice, please ? Thank you very much !
Alex. Nitulescu

In the TextChanged event of the text box you can perform a lookup of
the first value containing the StartsWith(txtF irsName.Text) within the
dropdownlists list of values. The first found item I'd set the
dorpdownlist's selected index value to that entry's index.

foreach(x=0; x<dropdownlist. items.count; x++)
if (dropdownlist.i tems[x].text.startswit h(txtfirstname. text))
{
dropdownlist.se lectedindex=x;
break;
}

This begs for the use of the Ajax Toolkit. You could do the lookup and
refresh the dropdownlist in the background using an asynchronous
callback by placing the controls on an Ajax update panel.
I should mention that using a dictionary of the text value and the
item's position in the list might speed up the search. What you'd have
to do is create a dictionary of every possible string as the key and
set the value to the index of the first item in the dropdownlist that
starts with that string value. By the size of your list (10,000+) you
might even want to create an index in sql server and use a sql query
to do this. Keeping this index up to date would require an insert/
update trigger in the database table containing the list of addresses.
This could potentially slow down inserts and updates to that table in
the database.

The trigger could be similar to

select top 1 Id
from addreses
where substring(first name,1,1] = @firstcharacter
order by descending

Another Idea would be to use a hybrid approach. You could create a
dictionary with the value being the first character of the name and
the key being the first index in the list beginning with that
character. You could then start a linear search using the StartsWith
method from that index forward until the first character changes. This
would limit the number of items you'd have compare to in the list for
any given string. Again, an sql index might speed the creation of this
dictionary with the same caveats as above.

Apr 9 '07 #3
Thank you, "WMAIN" ;-) Great ideas, I will start working on them/
thinking about it 1st thing tomorrow morning.

However, I still have a question/problem:

How could one NOT use TextChanged (this assumes hitting ENTER every
time you want to search - really incovenient !) and use a KeyPress
type of event instead ? Is it possibile ? A way would be, I think, to
download the whole list locally (just as I do, actually, when
populating the combo-box (I'm using a sproc)), and search there, in
some array/collectiion/special collection, maybe.... what do you
think ? That would not involve any trip to the server - the only thing
is that I know VB/VBScript, not JavaScript (I know NO JavaScript at
all), to write this kind of code. But I could try, nevertheless.

Thanks a lot ! :-)))
Alex.
On Apr 9, 12:04 pm, "wmain" <mainmeis...@gm ail.comwrote:
On Apr 9, 11:53 am, "wmain" <mainmeis...@gm ail.comwrote:


On Apr 9, 11:07 am, "Radu" <cuca_macaii2.. .@yahoo.comwrot e:
Hi. I have the following problem - I need to build a user-control in
asp.net (an ascx) to somehow allow the users to search by first name
or last name among a big (~10.000 records) email addresses database
(SQL server table). I am thinking of allowing them to type something
in EITHER the last name, EITHER the first name textbox, and on each
text change to show in a combobox the records starting with that
letter combination.
Say for example that you have the following email addresses:
Hardy
John Doe
John Foe
John Poe
Johny Roe
Johny Zoe
Laurel
.....
When you type in the FirstName textbox the string "John", the combo
box should position itself on John Doe. Hardy should still be visible
right above John Doe, if you open the combobox, but John Doe should be
selected. If you type Johny, it should position itself onto Johny Roe.
If you type Johnson, it should show the first element of the combobox,
a null string, since there is no Johnson in the list.
Similar functionality for the LastName textbox.
Finally, when you are happy with the selection in the combobox, say
"Johny Roe", you click a 'Search' button which will populate the
search form with Johny Roe's ID.
My problem is that I don't know how to best implement this. I'm
thinking of tying somehow keypresses with some server code which will
interogate the SQL server database. I'm afraid of the reaction time of
this control, though.
Question: How do I associate code with keypresses ? I can't use
Javascript for this, because I need to look up the string into SQL
tables on the server, and a textbox has only a TextChanged event.
Although I know how to write the server code, I still don't know how
to do this overall - and still I have seen something like that before,
and it worked great, and super-fast - actually I don't know if it
involved trips to the server, although I guess it did.
Do you have any advice, please ? Thank you very much !
Alex. Nitulescu
In the TextChanged event of the text box you can perform a lookup of
the first value containing the StartsWith(txtF irsName.Text) within the
dropdownlists list of values. The first found item I'd set the
dorpdownlist's selected index value to that entry's index.
foreach(x=0; x<dropdownlist. items.count; x++)
if (dropdownlist.i tems[x].text.startswit h(txtfirstname. text))
{
dropdownlist.se lectedindex=x;
break;
}
This begs for the use of the Ajax Toolkit. You could do the lookup and
refresh the dropdownlist in the background using an asynchronous
callback by placing the controls on an Ajax update panel.

I should mention that using a dictionary of the text value and the
item's position in the list might speed up the search. What you'd have
to do is create a dictionary of every possible string as the key and
set the value to the index of the first item in the dropdownlist that
starts with that string value. By the size of your list (10,000+) you
might even want to create an index in sql server and use a sql query
to do this. Keeping this index up to date would require an insert/
update trigger in the database table containing the list of addresses.
This could potentially slow down inserts and updates to that table in
the database.

The trigger could be similar to

select top 1 Id
from addreses
where substring(first name,1,1] = @firstcharacter
order by descending

Another Idea would be to use a hybrid approach. You could create a
dictionary with the value being the first character of the name and
the key being the first index in the list beginning with that
character. You could then start a linear search using the StartsWith
method from that index forward until the first character changes. This
would limit the number of items you'd have compare to in the list for
any given string. Again, an sql index might speed the creation of this
dictionary with the same caveats as above.- Hide quoted text -

- Show quoted text -

Apr 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5489
by: Jonathan | last post by:
I am hoping that someone more experienced than myself can point me towards what might be the fastest data lookup method to use for storing ip addresses. My situation is that I will need to maintain a list of perhaps 50 ip addresses to be used in a packet sniffing application. For each packet that goes through the application (which will be monitoring all traffic through a switch), I need to see if an entry for the source ip of that packet...
2
2741
by: someone | last post by:
Hi, I currently have an Access 97 database that includes a field for contact name of a user. This user will almost always have a valid email address contained in the personal address book of the person who inputs the records into the database. At present the person inputting the records has to manually look up the correct address and copy in into the field. I know that it should be possible to lookup that address by some form of...
8
2005
by: Steve Jorgensen | last post by:
Hi folks, I'm posting this message because it's an issue I come up against relatively often, but I can't find any writings on the subject, and I haven't been able to figure out even what key words one would use to look for it. First, in broad philosophical terms, code actually -is- data. Code is the data that's fed into a compiler, interpreter, or microprocessor that tells it what to do. Code execution is, then, just a form another...
26
2762
by: libsfan01 | last post by:
Hi all! Can anyone show me how to check and email field on a form for the existence of these two characters. Kind regards Marc
0
292
by: Radu | last post by:
Hi. I have the following problem - I need to build a user-control in asp.net (an ascx) to somehow allow the users to search by first name or last name among a big (~10.000 records) email addresses database (SQL server table). I am thinking of allowing them to type something in EITHER the last name, EITHER the first name textbox, and on each text change to show in a combobox the records starting with that letter combination. Say for...
7
2132
by: Chris Morley | last post by:
Hi, i have found out as i have developed the database i've ended up with a number of tables that have the same attributes. For instance, my suppliers and customers have the same fields for the address. Would it make more sense to create an additonal table and to reference the addressID in the address table? Some tables like employees have multiple addresses, like home address, next of kin address etc. Now this is more of an issue for...
4
1683
by: karen.homersham | last post by:
Just working through Apress Pro ASP NET.2.0.E Commerce in C Sharp. I am having problems compiling the following: using System; using System.Collections.Generic; using System.Text; namespace ECommerce.Common { public class Users
76
4053
by: lorlarz | last post by:
Crockford's JavaScript, The Good Parts (a book review). This shall perhaps be the world's shortest book review (for one of the world's shortests books). I like Douglas Crockford (because I am a crabby old man too; plus he _is_ smart and good).. But, how can he write a book on the good parts of JavaScript and not mention functions that address CSS & DOM? Weird. It's like
10
6917
by: Mike Miller | last post by:
Hi, Am wanting to send email with php and need to access the global outlook address book. Are there any examples/tutorials on how to do this? M
0
8678
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.