How do I set width with percent in code behind? The only option I can think of is taking the parent width and calculate by percent.i.e. TableRow.Width = Table.Width.Value * 25/100 (set table row with width equals to 25% of the table width). However, eventually, how do I set the table width in percent? Without the table width, the child controls cannot use its parent widths to calculate.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Will this not work? Although I’m not entirely sure why you’d want a table row to be 25% of an overall table’s width
TableRow.Width = new Unit("25%")
Method 2
.Net wrappers for html components dose not include “width” parameter( including the HtmlTableRow ). and for those containing the “width” property, a .toString() is needed on the given solution.
an other easy approach would be using inline CSS styles ( first line is the answer rest is just a usage sample which 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 the element
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0