Have you ever made an address book? What does it have? Addresses, names, emails, and maybe you can also send an email using your address book, right? How cool it would be if you have a list of people in your table with their addresses and when you click on a person's information you can see his physical address. In this article I will show you how easy it is to attach the parameters to the request sent to MapQuest. You can use any type of address finder website you wish to use, I will be using MapQuest in my example.
Making the database
Let's first make a simple database which contains Person ID, Name, and ZIP code. You can use the full address of a person but I have noticed that most of the time services like MapQuest are not able to locate the actual address. I will be using ZIP code for finding the address. Enter some data in the database and we are ready to go!
Displaying Data on the Page
Let's display data on the page by using a
DataGrid. All the addresses and ZIP codes you see below are added in your Address Book. Let's assume that your ZIP code is 77304. So we will be finding directions from your ZIP code to the ZIP codes in your address book. Here is how it will look like when you display the
DataGrid on the page.
Redirecting to MapQuest
I thought about this and could not find a better way to redirect to the directions page. There are several ways that you can perform it like opening the directions page in the new pop up window, or maybe in the frame. I chose a new page (not a pop up) because some browsers have pop up killers so on those browsers the pop up will not open, or in other words the pop up will be killed. Frames also had some problems since some browsers do not support frames. Keeping these reasons in front of me, I chose redirecting the same page to the directions page.
Implementing DataGrid Select Column Code
Time has come to code, so, in the
SelectedIndexChanged event, write this code:
private void ChangeSelection(object sender, System.EventArgs e)
string otherZipCode = myDataGrid.SelectedItem.Cells.Text;
string url = "http://www.mapquest.com/directions/main.adp?" +
otherZipCode + "&2ah=&idx=0&" +
Yeah, that's all you have to do. I just embedded the variables that contained the values of
otherZipCode in the URL, pretty simple right!