1

I'm building some Web Application using aspx and C# and i want to create an 2D String array in the java script but to initialize it with an array from my c# code. I used the "<% ... %> for it but it didn't work. My code is like this:

iconColors = new String[,];
protected void Page_Load(object sender, EventArgs e)
    { // some code that filling the array
    }  

in Java Script:

<script>
var seatColor = "<%= iconColors %>"; 
for (.... i and j....) {// its a double loop
 document.write("....."+iconColos[i,j]+"...");
}
</script>

again, it doesn't work. help somebody?

4

2 Answers 2

0

i guess this must work.

<script>
var seatColor = "<%= iconColors %>"; 
for (.... i and j....) {// its a double loop
  document.write("....."+seatColor [i][j]+"...");
}
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

@user1857251 You have iconColors, not seatColor in your loop.
0

There are no native 2D arrays in JavaScript. You need to create your own. I saw someone use this method: var arr = [[1,2],[3,4]]; (an array of arrays)

You'll have to adjust your server code to something that can serialize to that. An array of arrays probably work.

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.