Dynamically output table results?

S

Steve Franks

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
 
L

Lucas Tam

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....
 
A

aa7im

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top