Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Table/TableRow/TabelCell width by percent in code behind in asp.net?

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.

like image 758
Amumu Avatar asked Aug 31 '11 14:08

Amumu


People also ask

How do you set the width of a table?

To set the table width in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property width.

How do you set a fixed td width?

Using width attribute: The <td> tag has width attribute to control the width of a particular column. By assigning a numeric value to this attribute between 0 to 100 in terms of percentage(or you can use pixel format). We can restrict the column width up to that much percentage of the table's total width.

How do I make a table with different sized cells in HTML?

To manipulate the height or width of an entire table, place the size attribute (either "WIDTH=" or "HEIGHT=") within the <TABLE> code. To manipulate individual cells, place the size attribute within the code for that cell.


2 Answers

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%")
like image 143
John Avatar answered Oct 21 '22 21:10

John


.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

like image 5
Omid S. Avatar answered Oct 21 '22 22:10

Omid S.