Iteration in asp.net databinding
<p>Say I have an array like so in my code behind:</p>

<p>public static string[] fields = new string[]{"field1", "field2", "field3", "field4"};</p>

<p>I would like to use this array to retrieve fields in a gridview when it is databinding, like so:</p>

<pre><code>&lt;%# Eval("Field1")%&gt;
&lt;%# Eval("Field2")%&gt;
&lt;%# Eval("Field3")%&gt;
&lt;%# Eval("Field4")%&gt;
</code></pre>

<p>However, I have had a very difficult time figuring out how to iterate over my array (fields) to produce the above code. It does not want to parse any operators within the databinding server tags (&lt;%# %>) like so:</p>

<pre><code>&lt;%# foreach (string field in fields)
    {
       Eval(field);
    }
%&gt;
</code></pre>

<p>And I cannot find a way to reproduce the databinding behavior in regular server tags:</p>

<pre><code>&lt;% foreach (string field in fields)
    {
       Response.Write(DataBinder.Eval(object, field);
    }
%&gt;
</code></pre>

<p>The databinder.eval method takes a container object which I'm not sure I can access outside of the regular databinding tags. I have also tried using regular server tags to produce the iteration code surrounding the databinding code, but it is not able to access the variables of the iteration.</p>

<p><strong>EDIT:</strong></p>

<p>I should be more clear, in the end I want the values to end up on my page, not the field names themselves. My database might look something like:</p>

<pre><code>Field1 | Field2 | Field3 | Field4
       |        |        |
value1 | value2 | value3 | value4
</code></pre>

<p>and when is all said and done, my page should look like:</p>

<pre><code>value1
value2
value3
value4
</code></pre>

<p>BUT the fields array is dynamic, and may be different depending on the object, so statically accessing each index in the array won't work.</p>
