I have these data in thhe codebehind and tried to pass it to javascript function in various format: array of list, json string but no way to get data by a javascript var object. Here the last format of data in the code behind:
List<string>[] array2 = new List<string>[listLenght];
array2.Initialize();
for (int ii = 0; ii < listLenght; ii++)
{
array2[ii] = new List<string>();
array2[ii].Add(Convert.ToString(dt.Rows[ii][5]));
array2[ii].Add(Convert.ToString(dt.Rows[ii][9]));
array2[ii].Add(Convert.ToString(dt.Rows[ii][10]));
array2[ii].Add(Convert.ToString(dt.Rows[ii][11]));
}
Then tried to call javascriot in this way:
string createArrayScript = string.Format("var array2 = [{0},{1},{2},{3}];", string.Join(",",",",",", array2));
but return an error: FormatException was unhandled by user code The index (zero based) must be greater than or equal to zero and less than the size of the list of topics.
This is the call to the function: Page.ClientScript.RegisterStartupScript(this.GetType(), "registerPoiArray", createArrayScript, true);
Here the javascript var format:
var markers = Poi;
var markers = [
{
"title": "via Andria, Roma",
"lat": 41.8902643,
"lng": 12.6638589,
"description": "fdsad"
},
{
"title": "via canosa, Roma",
"lat": 41.8838417,
"lng": 12.5438227,
"description": "fdsad"
},
{
"title": "via taranto, Milano",
"lat": 45.4383343,
"lng": 9.1505354,
"description": "fdsad"
},
{
"title": "via barletta, Roma",
"lat": 41.9102707,
"lng": 12.4580826,
"description": "fdsad"
}];
I can not pass this array in javascript. Help me please