C# 动态调整表格单元格宽度
我正在动态地将行和列添加到表中,但无法调整第一列的宽度。。我尝试了所有可能的“单位”组合(新单位(300,单位类型.点))-但没有乐趣。它总是显示该列中数据的列宽与长度,但我希望它是固定的。请问这里怎么了C# 动态调整表格单元格宽度,c#,asp.net,C#,Asp.net,我正在动态地将行和列添加到表中,但无法调整第一列的宽度。。我尝试了所有可能的“单位”组合(新单位(300,单位类型.点))-但没有乐趣。它总是显示该列中数据的列宽与长度,但我希望它是固定的。请问这里怎么了 TableRow tr = new TableRow(); TableCell tc = new TableCell(); tc = new TableCell(); tc.ID = "tcResource"; tc.Text = "Resource_Name"; Unit uWid
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);
TableRow tr=newtablerow();
TableCell tc=新的TableCell();
tc=新表单元格();
tc.ID=“tcResource”;
tc.Text=“资源名称”;
单位宽度=新单位(300,单位类型点);
tc.宽度=uWidth;
tr.Cells.Add(tc);
对于(i=1;i您应该使用CSS样式调整列宽,而不是在服务器端进行调整。请将其放入CSS文件中:
td.tcResouce{ width:300px }
并在ASP.Net页面中添加链接:
<link rel="stylesheet" type="text/css" href="/path/to/file.css">
您应该使用CSS样式调整列宽,而不是在服务器端进行调整。请将其放入CSS文件中:
td.tcResouce{ width:300px }
并在ASP.Net页面中添加链接:
<link rel="stylesheet" type="text/css" href="/path/to/file.css">
试试这个
Unit width = new Unit(30, UnitType.Pixel);
TableCell cell = new TableCell();
cell.Width = width;
试试这个
Unit width = new Unit(30, UnitType.Pixel);
TableCell cell = new TableCell();
cell.Width = width;
如果您将代码添加到原始问题而不是粘贴到注释中,这将是一件好事。“重复”:如果您将代码添加到原始问题而不是粘贴到注释中,这将是一件好事。“重复”:我希望在服务器端(动态)执行此操作我希望在服务器端(动态)执行此操作