locked
java script array items not clear RRS feed

  • Question

  • User229488726 posted

    in project my requirement  

    a google map  with multipal  marker when i  run the code 1st time it work fine  but when i select another item from drop down list its  not work 

    new values not shows in map only show the old value  my code is 

    is .cs page 

    public string ConvertDataTabletoString()
    {
    int flag=Convert.ToInt32(ViewState["flag"]);
    int bankid = Convert.ToInt32(ViewState["bankid"]);
    int branchid = Convert.ToInt32(ViewState["branchid"]);
    int stateid = Convert.ToInt32(ViewState["stateid"]);
    int distid = Convert.ToInt32(ViewState["distid"]);
    int cityid = Convert.ToInt32(ViewState["cityid"]);

    DataTable dt = objcustomer.searchbankbranch(flag,bankid,branchid,stateid,distid,cityid);

    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
    List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
    rows.Clear();
    Dictionary<string, object> row;

    foreach (DataRow dr in dt.Rows)
    {
    row = new Dictionary<string, object>();
    foreach (DataColumn col in dt.Columns)
    {
    row.Add(col.ColumnName, dr[col]);
    }
    rows.Add(row);
    }
    return serializer.Serialize(rows);
    }

    and the java script is 

    <script type="text/javascript">

    function loadmap () {
    debugger;


    var markers = JSON.parse('<%=ConvertDataTabletoString() %>');
    var mapOptions = {
    center: new google.maps.LatLng(markers[0].Latitude, markers[0].Longitude),
    zoom: 8,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var infoWindow = new google.maps.InfoWindow();
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    for (i = 0; i < markers.length; i++) {
    var data = markers[i]
    var myLatlng = new google.maps.LatLng(data.Latitude, data.Longitude);
    var marker = new google.maps.Marker({
    ,
    map: map,
    title: data.Name
    });

    (function (marker, data) {

    google.maps.event.addListener(marker, "click", function (e) {
    //infoWindow.setContent(data.description);
    if (data.totallocker > 0)
    {
    infoWindow.setContent('<p>Branch Name: ' + data.Name + '</p>' +
    '<p>Address: ' + data.Address + '</p>' +
    '<p>available Locker: ' + data.totallocker + '</p>' +
    '<a href="#" value=' + data.branchid + ' onclick="myFunction(this)">Apply Locker</a>'
    );
    }
    else {
    infoWindow.setContent('<p>Branch Name: ' + data.Name + '</p>' +
    '<p>Address: ' + data.Address + '</p>' +
    '<p>available Locker: ' + data.totallocker + '</p>'

    );
    }
    infoWindow.open(map, marker);
    });
    })
    (marker, data);
    debugger;
    }

    }

    </script>

    how to do this please help me 

    Thursday, February 4, 2016 3:53 PM

Answers