fill gridview cell-by-cell
<p>I want to populate GridView below with images:</p>

<pre><code>&lt;asp:GridView ID="GrdDynamic" runat="server" AutoGenerateColumns="False"&gt;
    &lt;Columns&gt;
    &lt;/Columns&gt;
&lt;/asp:GridView&gt;
</code></pre>

<p>The code below iterates through directory, then I collect image titles and want them to be populated in gridview. code in bold is not working well, gridview is only filled with the last image in list.</p>

<pre><code>List&lt;string&gt; imagelist = new List&lt;string&gt;();

protected void Page_Load(object sender, EventArgs e)
{
    foreach (String image in Directory.GetFiles(Server.MapPath("example/")))
    {
        imagelist.Add("~/example/" + Path.GetFileName(image));
    }
    loadDynamicGrid(imagelist);
}

private void loadDynamicGrid(List&lt;string&gt; list)
{
    DataTable dt = new DataTable();

    DataColumn dcol = new DataColumn(NAME, typeof(System.String));
    dt.Columns.Add(dcol);

    dcol = new DataColumn("NAME1", typeof(System.String));
    dt.Columns.Add(dcol);

    dcol = new DataColumn("NAME2", typeof(System.String));
    dt.Columns.Add(dcol);

    dcol = new DataColumn("NAME3", typeof(System.String));
    dt.Columns.Add(dcol);

    DataRow drow = dt.NewRow();
            dt.Rows.Add();
            dt.Rows.Add();

            **for (int i = 0; i &lt; dt.Rows.Count; i++)
            {
                for (int j = 0; j &lt; dt.Columns.Count; j++)
                {
                    foreach (string value in list)
                    {
                        dt.Rows[i][j] = value;
                    }
                }
            }**

    foreach (DataColumn col in dt.Columns)
    {
        ImageField bfield = new ImageField();

        bfield.DataImageUrlField = NAME;

        bfield.HeaderText = col.ColumnName;

        GrdDynamic.Columns.Add(bfield);
    }

    GrdDynamic.DataSource = dt;

    GrdDynamic.DataBind();
}
</code></pre>

<p>how to fill gridview cell-by-cell only with available amount of images?</p>

<p>i know it is easy, i tried various methods like: <code>dt.Rows.Add(list);</code> and some other attempts, but they didn't work. i'm very stupid.
i'd be glad for any help.</p>
