The code below allow me to load only a single pushpin into the map but I need to load all pushpin to the map.How can I do it

server code:

Private Sub DisplayRecord()

'Display record based on User ID


'retrieve data from database and place in textbox


Dim mySelectQuery As String = "SELECT * from Map"

Dim cmd As SqlCommand = New SqlCommand(mySelectQuery)

cmd.Connection = cnn



cmd.Parameters.AddWithValue("Lat", txtLat.Text)

cmd.Parameters.AddWithValue("Long", txtLong.Text)

cmd.Parameters.AddWithValue("Level", txtLevel.Text)

cmd.Parameters.AddWithValue("Name", txtName.Text)

Dim dtr As SqlDataReader = cmd.ExecuteReader()

Do While dtr.Read()

txtLat.Text = dtr("Latitude")

txtLong.Text = dtr("Longtitude")

txtLevel.Text = dtr("ZoomLevel")

txtName.Text = dtr("Title")




End Try

Catch ex As Exception

Throw New Exception(ex.Message)

End Try

End Sub

Client Code :

function GetMap()


map = new VEMap('myMap');

map.LoadMap(new VELatLong(36.80928470205939, 97.998046875), 4 ,'r' ,false);

// map.AttachEvent('onclick', onMapClick);

map.AttachEvent('onclick', myEventTester); //change to your event

map.AttachEvent("onchangeview", GetPinData);



function GetPinData()


var pin_id=0;

var locs = new Array;

var loc = new VELatLong(document.getElementById('txtLat').value, document.getElementById('txtLong').value);


for (i=0; i < locs.length; i++)


var pin1 = new VEPushpin(pin_id, locsIdea, null, 'A point', 'location number '+ i);





function DoBestMap(locs)




Re: How to do a while loop to load pushpin into map



I researched this issue over the weekend. It's not a simple solution, but I learned a ton. In a nutshell, I used Ajax to call a web service through the Javascript that allowed me to pass in all the data for all the pushpins in my database. I aso created an admin page to add new pushpins at anytime. The actual map is a usercontrol that I can just drop on any page in my project. The references i used were the Virtual Earth SDK, the Ajax site on, and various articles on using Ajax to call a web service.

The code isn't pretty in some parts, and I'm still in developement, but here goes:

My user control:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="mapWorld.ascx.vb" Inherits="User_Controls_mapWorld" %>



<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<script src="" type="text/javascript"></script>

<script type="text/javascript" src="../Scripts/map.js">



<body onload="LoadMap();">

<asp:ScriptManager ID="ScriptManager1" runat="server">


<asp:ServiceReference Path="~/WebServices/service.asmx" />



<div id='myMap' style="position:relative; width:600px; height:600px;"></div>


external .js file:

var map = null;

var _Pins = [];

function LoadMap()



World.service.GetPins(LoadPins, onError);


function GetMap()


map = new VEMap('myMap');

map.LoadMap(new VELatLong(30.265137, -90.920085), 10 ,'h' , false);




function LoadPins(results)


if (results != null && results != 'undefined') {


_Pins = results.Pins;



if (results = null ) {

document.write("No Results");



function AddPins()



for (var i=0;i<_Pins.length;i++) {

var pin = new VEPushpin(


new VELatLong( _PinsIdea.Lat, _PinsIdea.Lon),








function onError(results)




As you can see I call the webservice World.service.GetPins(LoadPins, onError); where the namespace is World, the web service name is service and the function is GetPins. This calls to a PinManger file that gets the pins from the database. I did use Dan Wahlin's weblog alot, as I found it very useful Remeber that when you create the webservice, you have to add in scripting services so that the Javascript can use it.

After I was done with that phase of the project, I looked back to see that is really a great solution. Just had to battle through learning all of it. I had very limited knowledge of web services and Ajax before, but alot more now. If you have any further issues or questions, you can post here or contact me directly. Posting here would be better, as it will help others.

Hope this helps.

Re: How to do a while loop to load pushpin into map



Other than web service is there any way to do it Can I populate the data into a datagrid and then read from there Do anyone know how to retrieve data from datagrid document.getElementById('txtLat').value is to get textbox value,so how to get datagid value

Re: How to do a while loop to load pushpin into map

Derek Chan

What your looking to do is throw all your data inside a <div> tag, maybe separated by an identifier (eg: comma), and then parse out all the data inside that tag. It does however, have the drawback of the data easily being viewed through the source (which you would experience reading from generated datagrids anyways).

However if you really need it inside datagrids, your going to need to encase the text inside an html element with an associated id, such as a <div> tag which again really defeats the purpose of using datagrids (hence what I suggest above)

Hope that helps,

Re: How to do a while loop to load pushpin into map

Jared H

For purposes of displaying collections, I'd make your database call and format the output as a GeoRSS file and then add the pins as a single layer rather than looping over an array of pins and calling the individual add pushpin method each time. This would definitely be quicker for larger datasets and reduce the processing overhead on your clients' browser(s).