---
title: "Adding rows dynamically in a table in C# while populating data from sqlserver"  
description: "Adding rows dynamically in a table in C# while populating data from sqlserver"  
author: "Anonymous User"  
published: 2014-12-09  
updated: 2014-12-10  
canonical: https://www.mindstick.com/forum/12775/adding-rows-dynamically-in-a-table-in-c-sharp-while-populating-data-from-sqlserver  
category: "asp.net"  
tags: ["c#", "sql server"]  
reading_time: 1 minute  

---

# Adding rows dynamically in a table in C# while populating data from sqlserver

I am [retrieving data](https://www.mindstick.com/forum/12885/how-to-retrieving-data-from-sql-server-and-adding-it-to-arraylist) from [sqlserver](https://www.mindstick.com/forum/33737/between-condition-in-sqlserver) using [Dropdown list](https://www.mindstick.com/forum/760/dropdown-list-open-hide-behind-another-dropdown-list-on-ie-7) box [selected value](https://www.mindstick.com/forum/525/get-selected-value-of-datagridviewcomboboxcolumn) and storing it in an [arraylist](https://www.mindstick.com/articles/11973/arraylist-class-in-c-sharp). Now the [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is how to retieve the arraylist [values](https://www.mindstick.com/forum/327/sum-textbox-values) and display in the table.

## Replies

### Reply by Anonymous User

Use it like below

```
    ArrayList myArrayList = new ArrayList();     //Fill ArrayList values from the SQL Server    myArrayList.Add("Hello");    myArrayList.Add("World");     Table table = new Table();     foreach (var item in myArrayList)    {        TableRow tr = new TableRow();        TableCell tc = new TableCell();        //Add Arraylist item into TableCell to display it        tc.Text = item.ToString();        tr.Cells.Add(tc);        table.Rows.Add(tr);    }
```

### Reply by Anonymous User

If you are using asp.net mvc you can use something like this:

```
<table>    @foreach (var item in List) {    <tr>        <td>           item.somethingA        </td>        <td>           item.somethingB        </td>     </tr>}</table>
```

etc to create table


---

Original Source: https://www.mindstick.com/forum/12775/adding-rows-dynamically-in-a-table-in-c-sharp-while-populating-data-from-sqlserver

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
