Dynamically output table results?

Discussion in 'ASP .Net' started by Steve Franks, Sep 10, 2005.

  1. Steve Franks

    Steve Franks Guest

    Can someone please recommend a good way in ASP.NET 1.1 to dynamically create
    a HTML table to display some results I have in local variables?

    For example, I want my HTML output to look like this:

    Magazines (table header)
    avg price: 4.50
    total sold: 200
    left in stock: 130

    Revenue
    today: 2000
    year to date: 4500
    sale running: False

    Please note a couple of things:

    1) each table will have the same html styles, format, and fonts. However
    the properties shown for each table (such as avg price, total sold, etc) are
    different, as shown in that example.

    2) this data is not coming from a database or record set. Rather, I have
    each value in its own local variable from the results of other business
    logic. For example I have the following variables:

    varAvgPrice = 4.50
    varTotalSold=200
    varInStock=130
    varToday=2000
    varYearToDate=4500
    varSaleRunning=False

    Now I could just hard code a table like this
    <td>avg price</td> <td> <% = varAvgPrice %> </td>
    but I have a few hundred results to display.

    So instead I would rather create some sort of routine or use some sort of
    control where I can pass it the header to use for the table, a list of the
    tables properties and values to display for each table property. What are
    some good ways to go about this?

    Thanks,

    Steve
    Steve Franks, Sep 10, 2005
    #1
    1. Advertising

  2. Steve Franks

    Lucas Tam Guest

    "Steve Franks" <> wrote in
    news::

    > Can someone please recommend a good way in ASP.NET 1.1 to dynamically
    > create a HTML table to display some results I have in local variables?


    You can use the Table, TableRow, TableCell classes to output dynamically.

    Or use a DataGrid...

    Or a DataList....

    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.

    Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
    Lucas Tam, Sep 10, 2005
    #2
    1. Advertising

  3. Steve Franks

    aa7im Guest

    Load your variables and values into an ArrayList for each table and
    then bind to a DataGrid or DataList:

    //Create this struct in your codebehind class or somewhere available to
    the codebehind
    public struct Variable
    {
    private string _name;
    private string _data;

    public Variable(string name,string data)
    {
    this._name = name;
    this._data = data;
    }

    public string Name
    {
    get { return this._name; }
    set { this._name = value; }
    }

    public string Data
    {
    get { return this._data; }
    set { this._data = value; }
    }
    }

    //Then you can load yours vars and bind like this...
    ArrayList vars = new ArrayList();
    vars.Add(new Variable("varAvgPrice","4.50"));
    vars.Add(new Variable("varTotalSold","200"));
    vars.Add(new Variable("varInStock","130"));

    //dgTest is a DataGrid on the page
    dgTest.DataSource = vars;
    dgTest.DataBind();
    aa7im, Sep 10, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page