asp.net C#, Select html elements to process at run time
<p>Good Afternoon,</p>

<p>I have a html aspx page that has many many div elements. these div elements for a grid. The size of grid is selected client side and the div element are generated server side through a request. The div elements generated are something like this:</p>

<pre><code>&lt;div id="cell_0_0"&gt;&lt;/div&gt;
&lt;div id="cell_0_1"&gt;&lt;/div&gt;
&lt;div id="cell_0_2"&gt;&lt;/div&gt;
&lt;div id="cell_0_3"&gt;&lt;/div&gt;

&lt;div id="cell_1_0"&gt;&lt;/div&gt;
&lt;div id="cell_1_1"&gt;&lt;/div&gt;
etc...
etc...
</code></pre>

<p>when the grid is filled with integer values from the user, the values can be accessed by the server, so the server needs to get the values of these elements. This is simple.</p>

<pre><code>int value1 = cell_0_0.innerHTML;
int value2 = cell_0_1.innerHTML;
</code></pre>

<p>The problem is... The amount of divs generated by the server are decided at runtime.
(on client input, e.g. 4x4, 5x5 .. 9x9 grid)</p>

<p>So the divs can range from div id="cell_0_0" to div id="cell_4_4" or from cell_0_0 to cell_9_9.</p>

<p>Now I could have muliple functions on the server like: (pseudocode)</p>

<pre><code>if grid is 5x5
    int value5x5-1 = cell_0_0.innerHTML;
    ... ...
    int value5x5-25 = cell_5_5.innerHTML;

if grid is 9x9
    int value9x9-1 = cell_0_0.innerHTML;
    ... ...
    int value9x9-81 = cell_9_9.innerHTML
</code></pre>

<p>The problem is... these functions would be HUGE! for a 9x9 grid, there are 81 cells, so thats 81 procedural assisngments!</p>

<p>In javascript, I iterate through the cells using a for loop</p>

<pre><code>for (var i = 0; i &lt; gridSize; i++) {
    for (var j = 0; i &lt; gridSize; j++) {
        document.getElementById( "cell_" + i + "_" + j );
    }
}
// as you can see the cell ids are constructed as the loop progresses, because the parameter is a string
</code></pre>

<p>Finally... The question is... is there any way... I can get the server side C# code to dynamically iterate through the cell variables depending on how many cells there are.</p>

<p>If Not... What would be the best method to achieve such a problem?</p>

<p>Sorry for the long ass explanation, wanted to make sure you knew exactly what I was on about!</p>

<p>I know its a weird Question, Sorry if there is any confusion:)</p>

<p>Thanks,
Alex </p>
