Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Can anyone tell me how to switch between java-script functions in asp.net page? I have made 2 C# Functions "1 is for show all added events from database Google on map" & 2nd is "Show events with respect to selected parameters from the Drop-down list".1st c# function is running OK but not the 2nd one Please HELP???
Posted
Comments
Sergey Alexandrovich Kryukov 2-Dec-13 16:18pm    
There is no such "switching" problem, but there can be a problem with you code design. And we don't have your code sample to figure out what's wrong.
—SA
S.M.Arsalan 2-Dec-13 16:28pm    
please see the code below
S.M.Arsalan 2-Dec-13 16:24pm    
protected void Page_Load(object sender, EventArgs e) {

}

public string ConvertDataTabletoString()
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection("Data Source=arsalan\\sqlexpress;Initial Catalog=FindEvent;Integrated Security=true"))
{
using (SqlCommand cmd = new SqlCommand("select title=Chief-guest,lng=longitude,lat=Latitude,Comment from Event", con))
{

con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);

da.Fill(dt);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<dictionary<string, object="">> rows = new List<dictionary<string, object="">>();



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);
}
Sergey Alexandrovich Kryukov 2-Dec-13 16:38pm    
Please move the code to the question by clicking at improve question. Use the tags <pre lang="javascript"> for formatting code.
—SA
S.M.Arsalan 2-Dec-13 16:27pm    
at map.aspx

<script type="text/javascript" src = "https://maps.googleapis.com/maps/api/js?key=AIzaSyDr1aftH-xmixjAyUBfumW886tqSk_vo-4&sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var markers = JSON.parse('<%=ConvertDataTabletoString() %>');
var markers = JSON.parse('<%=ConvertDataTabletoString1() %>');
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
// marker:true
};
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.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title
});
(function (marker, data) {

// Attaching a click event to the current marker
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
})(marker, data);
}
}
</script>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900