2013-08-16 127 views
1

我正在動態地將行和列添加到表格中,但我無法調整第一列的寬度..我嘗試了所有可能的「單元」組合(新單元(300,單元類型。點)) - 但沒有喜悅。它總是顯示列中數據的列寬和長度,但我希望它是固定的。請問這裏有什麼問題。動態調整表格單元格寬度

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); 
+0

我們展示您的代碼 –

+1

這將是很好的,如果您將代碼添加到原始問題中,而不是將其粘貼到評論中。 –

+1

「Duplicate」:http://stackoverflow.com/questions/7258735/how-to-set-table-tablerow-tabelcell-width-by-percent-in-code-behind-in-asp-net –

回答

0

您應該用CSS樣式調整列寬,而不是在服務器端調整。把這個CSS文件:

td.tcResouce{ width:300px } 

,並在你的ASP.Net頁面添加一個鏈接:

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

我想在服務器端做(動態) – user

4

試試這個

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

cell.Width = width; 
+0

爲我工作:) – sunnysidedown916