Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Dynamically output table results? (http://www.velocityreviews.com/forums/t109611-dynamically-output-table-results.html)

Steve Franks 09-10-2005 03:15 PM

Dynamically output table results?
 
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







Lucas Tam 09-10-2005 06:57 PM

Re: Dynamically output table results?
 
"Steve Franks" <please@postreplyhere.com> wrote in
news:NoydnRNlPpIEZb_eRVn-3w@comcast.com:

> 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 (REMOVEnntp@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com

aa7im 09-10-2005 08:21 PM

Re: Dynamically output table results?
 
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();



All times are GMT. The time now is 07:57 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.