title: how to pass c# datatable to a javascript function
body: <p>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:</p>
  
  <pre><code>    List&lt;string&gt;[] array2 = new List&lt;string&gt;[listLenght];
      array2.Initialize();
  
      for (int ii = 0; ii &lt; listLenght; ii++)
      {
      array2[ii] = new List&lt;string&gt;();
         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]));
  
      }
  </code></pre>
  
  <p>Then tried to call javascriot in this way:</p>
  
  <pre><code>   string createArrayScript = string.Format("var array2 = [{0},{1},{2},{3}];",         string.Join(",",",",",", array2));
  </code></pre>
  
  <p>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.</p>
  
  <p>This is the call to the function:
      Page.ClientScript.RegisterStartupScript(this.GetType(), "registerPoiArray",      createArrayScript, true);</p>
  
  <p>Here the javascript var format:</p>
  
  <pre><code>    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"
  }];
  </code></pre>
  
  <p>I can not pass this array in javascript. Help me please </p>