How to set table / TableRow / TabelCell as a percentage of code in asp.net?

How to set width with percentage in code? The only option I can think of is to take the width of the parent and calculate .ie TableRow.Width = Table.Width.Value * 25/100 (set the table row with a width equal to 25% of the width of the table). However, in the end, how to set the table width as a percentage? Without table width, child controls cannot use their parent width for calculation.

+8
c # code-behind
source share
2 answers

Wouldn't that work? Although I'm not quite sure why you want the table row to be 25% of the total table width

 TableRow.Width = new Unit("25%") 
+22
source share

.Net wrappers for html components do not include a width parameter (including HtmlTableRow ). and for those that contain the width property, this solution requires .toString ().

another simple approach would be to use inline CSS styles (the first line is the answer, this is just a usage pattern that I used to test the solution):

  c.Style.Add("width", "25% !important"); c.Style.Add("border-color", "Red"); c.Style.Add("border-style", "solid"); c.Style.Add("border-width", "1px"); 

where c is an element

+5
source share

All Articles