Google Map Dynamic Data Generated from SQL Database C# .Net Codebehind
public class MapDataAccess
{
private SqlConnection conn;
public MapDataAccess()
{
this.conn = new SqlConnection(Global.CMCONNSTRING);
}
public SqlDataReader GetGeoCodesCountry(string strCountry)
{
string queryString="SELECT *";
queryString += " FROM People where ADR1_COUNTRY='" + strCountry + "' order by lname";
return SqlHelper.ExecuteReader(conn, CommandType.Text, queryString);
}
}
Code behind codes that returns Google Map data xml file. You could pass back Session["CountryCode"] by set up a postback event on dropdownlist from client:
private void Page_Load(object sender, System.EventArgs e)
{
MapDataAccess da = new MapDataAccess();
SqlDataReader dr;
string strCountry = Session["CountryCode"].ToString();
dr = da.GetGeoCodesCountry(strCountry);
Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter objX = new XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8);
objX.WriteStartElement("markers");
while(dr.Read())
{
if ((dr["LATTITUDE"].ToString() != "")&&(dr["LONGITUDE"].ToString()!=""))
{
objX.WriteStartElement("marker");
objX.WriteAttributeString("lat", dr["LATTITUDE"].ToString());
objX.WriteAttributeString("lng",dr["LONGITUDE"].ToString());
objX.WriteEndElement();
}
}
da.closeConn();
objX.WriteEndElement();
objX.Flush();
objX.Close();
Response.End();
}
Note: These are not complete list of my original codes, please make necessary changes according to your situation.