ADDING ROWS DYNAMICALLY IN A TABLE IN C# WHILE POPULATING DATA FROM SQLSERVER

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 845  View(s)
Ratings:
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.

  1. john rob

    Post:108

    Points:756
    Re: Adding rows dynamically in a table in C# while populating data from sqlserver

    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

  1. Chintoo Semi

    Post:135

    Points:947
    Re: Adding rows dynamically in a table in C# while populating data from sqlserver

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

        }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!