473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2395
On Apr 9, 11:07 am, "Radu" <cuca_macaii2...@yahoo.comwrote:
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(txtFirsName.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.items[x].text.startswith(txtfirstname.text))
{
dropdownlist.selectedindex=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...@gmail.comwrote:
On Apr 9, 11:07 am, "Radu" <cuca_macaii2...@yahoo.comwrote:
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(txtFirsName.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.items[x].text.startswith(txtfirstname.text))
{
dropdownlist.selectedindex=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(firstname,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...@gmail.comwrote:
On Apr 9, 11:53 am, "wmain" <mainmeis...@gmail.comwrote:


On Apr 9, 11:07 am, "Radu" <cuca_macaii2...@yahoo.comwrote:
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(txtFirsName.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.items[x].text.startswith(txtfirstname.text))
{
dropdownlist.selectedindex=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(firstname,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
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...
2
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...
8
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...
26
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
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...
7
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...
4
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...
76
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...
10
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.