views:

208

answers:

2

I'm creating a table in an asp.net code behind dynamically, and I want to have a footer row that only has 2 cells. The first should span all the columns in the table-1. Is there some way other then keeping track of the # of columns in the table manually for me to set the colspan to be # of all the columns in the table-1?

Preferably a HTML or CSS solution?

+2  A: 

Colspan can't be done with CSS. It's structural rather than stylistic so it's pure HTML.

No you can't specify "all but one" as a colspan. The best you can do is colspan="0", which will span the remaining columns in the column group but to take advantage the <colgroup> at the top will need to know the number of columns anyway and be define statically.

See Tables in the HTML spec:

colspan = number [CN]

This attribute specifies the number of columns spanned by the current cell. The default value of this attribute is one ("1"). The value zero ("0") means that the cell spans all columns from the current column to the last column of the column group (COLGROUP) in which the cell is defined.

But basically this just kicks the can down the street and I don't know what the browser support is like so it doesn't necessarily buy you anything.

You'll either need to know the number of columns when you generate the HTML or use Javascript.

cletus
Ok, I guess I'll just track # of columns during generation. Thanks
jamone
A: 

Sorry this isn't an HTML or CSS solution... I'm only suggesting it because I don't think there is an HTML or CSS solution that will work cross-browser/cross-broweser version.

You could convert the table to an Asp:Table and then use the first row's Cells.Count...

But it would probably be more work than tracking the number of columns added the way you're doing it now. BUT it would not depend on Browser support as it would all be in the code-behind.

David Stratton