Home > DeveloperSection > Forums > Adding rows dynamically in a table in C# while populating data from sqlserver
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    December-09-2014 11:43 PM

 ASP.Net C#  SQL Server 
Ratings:


 2 Reply(s)
 590  View(s)
Rate this:

I am retrieving data from sqlserver using Dropdown list box selected value and storing it in an arraylist. Now the problem is how to retieve the arraylist values and display in the table.



john rob

Total Post:108

Points:756
Posted on    December-10-2014 5:42 AM

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


Chintoo Semi

Total Post:135

Points:947
Posted on    December-10-2014 6:40 AM

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);

    }


Don't want to miss updates? Please click the below button!

Follow MindStick