Passing c# datatable into javascript multi dimentional array list -



Passing c# datatable into javascript multi dimentional array list -

i need pass datatable asp.net c# java script in next format.

var markers = [ { "title": 'campbell donald', "lat": '35.821201', "lng": '-78.703884', "description": '3100 bluish ridge rd,raleigh,nc,27612' }, { "title": 'hoffman byron', "lat": '35.723053', "lng": '101.7061447', "description": '421 n holly ave,siler city,nc,27344' }, { "title": 'jalan intan (gombak)', "lat": '3.22317', "lng": '101.71588', "description": 'jalan intan (gombak), kuala lumpur, wilayah persekutuan kuala lumpur, 53100' }, { "title": 'jalan madrasah', "lat": '3.218515', "lng": '101.717801', "description": 'jalan madrasah, kuala lumpur, wilayah persekutuan kuala lumpur, 53100' }

];

i tried assign marker variable in way code.

datatable dthcp = dbutil.gethcpbymapdistance(); var serializer = new javascriptserializer(); stringbuilder sb = new stringbuilder(); sb.append("<script>"); sb.append("var markers = [];"); foreach (object datarow in dthcp.rows) { sb.append("markers.push('" + string.format("var jsarray = {0}", serializer.serialize(datarow)) + "');"); } sb.append("</script>"); clientscript.registerstartupscript(this.gettype(), "testarrayscript", sb.tostring(),true);

my java script part

var markers = []; window.onload = function () { var mapoptions = { center: new google.maps.latlng(markers[1].lat, markers[1].lng), zoom: 14, maptypeid: google.maps.maptypeid.roadmap }; var map = new google.maps.map(document.getelementbyid("dvmap"), mapoptions); var infowindow = new google.maps.infowindow(); (i = 1; <= markers.length; i++) { var info = markers[i - 1] var mylatlng = new google.maps.latlng(data.lat, data.lng); var marker = new markerwithlabel({ position: mylatlng, map: map, title: data.title, labelcontent: i, labelanchor: new google.maps.point(6, 34), labelclass: "labels", // css class label labelinbackground: false }); (function (marker, data) { google.maps.event.addlistener(marker, "click", function (e) { infowindow.setcontent(data.description); infowindow.open(map, marker); }); })(marker, data); } }

please help me through this. in advance.

basically looking json rather javascript array.

you utilize javascriptserializer class:

using system.web.script.serialization; var json = new javascriptserializer().serialize(obj);

i suggest utilize web-method or generic http handler type of request.

javascript c# asp.net

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -