1

I'm dynamically adding the rows and columns to a Table, but i am unable to adjust the first column's width.. i tried all possible combinations of "Unit" (new Unit(300, Unit Type.Point) ) - but no joy. It always shows the column-width to length of the data in that column, but i wanted it to be fixed. what's wrong here please.

TableRow tr = new TableRow(); 
TableCell tc = new TableCell(); 
tc = new TableCell(); 
tc.ID = "tcResource"; 
tc.Text = "Resource_Name"; 
Unit uWidth = new Unit(300, UnitType.Point); 
tc.Width = uWidth; 
tr.Cells.Add(tc); 
for (i = 1; i <= 365; i++) 
{ 
  tc = new TableCell(); 
  tc.ID = "tc" + i.ToString(); 
  tc.Text = dtStart.AddDays(i).ToString("dd/MM") ; 
  dtRange[i - 1] = dtStart.AddDays(i ); 
  tr.Cells.Add(tc); 
} 
tHoliday.Rows.Add(tr); 
2
  • 1
    It will be good if you add your code to original question instead of pasting it in comment. Commented Aug 16, 2013 at 11:26
  • 1
    "Duplicate": stackoverflow.com/questions/7258735/… Commented Aug 16, 2013 at 11:42

2 Answers 2

5

Try this

Unit width = new Unit(30, UnitType.Pixel);
TableCell cell = new TableCell();

cell.Width = width;
Sign up to request clarification or add additional context in comments.

Comments

0

You should be adjusting the columns width with a CSS style, not by doing it server side. Put this in a CSS file:

td.tcResouce{ width:300px }

and add a link in your ASP.Net page:

<link rel="stylesheet" type="text/css" href="/path/to/file.css">

1 Comment

I want to do it on server side(dynamically)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.