0

I have an application based on google map, in which I need to use a javascript matrix (2d array) for the map's parameters.

I have a datatable with the information at my code behind file:

..query code, getting value from the db..
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);

How do I pass this datatable values into a js two denominational array?

Thanks

1
  • Hi Oded, implementing a js dataset using JSON. Commented Apr 4, 2012 at 10:04

3 Answers 3

1

An easy way is on the aspx page to have where appropriate

<script type="text/javascript>
    var mapData = <%=mapData%>
</script>

Then in your code behind create a public string called mapData and assign it as a json string. e.g.

mapData = "{({name:'blah',lat:10.223,long:57.899},{etc})};
  • obviously loop through your dataset to create the string.

You can then use it in your javascript on the page

Sign up to request clarification or add additional context in comments.

Comments

0

You can use Ajax for retrieve the data table as an array from the server.

public ArrayList ConvertDT(ref DataTable dt)
{
   ArrayList converted = new ArrayList(dt.Rows.Count);
    foreach (DataRow row in dt.Rows)
            converted.Add(row);
    return converted;
    }

then array list convert into array and send back as a response to the client

http://www.dreamincode.net/forums/topic/91826-datatable-to-array/

Comments

0

Why not use Jquery Ajax? With Jquery Ajax you can bring data from server side to client side.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.