麻烦格式化表的单元格

时间:2014-12-31 18:57:10

标签: c# alignment tablecell

我有一个包含1行和3列的表格。但是列没有正确对齐。它显示如下:

enter image description here

Table _tbRequiredDocFormat = new Table();
TableRow row_requiredDocCount = new TableRow();                       
TableCell cellLabel = new TableCell();
TableCell cellFileInput = new TableCell();
TableCell cellBtn = new TableCell();  
//add label, RadAsyncUpload and Button to cells.//
//formatting as below::
this._tbRequiredDocFormat.Rows[requiredDocCount].Cells[0].Width = Unit.Percentage(30);
this._tbRequiredDocFormat.Rows[requiredDocCount].Cells[0].HorizontalAlign = HorizontalAlign.Right;                       
this._tbRequiredDocFormat.Rows[requiredDocCount].Cells[0].VerticalAlign = VerticalAlign.Middle;
this._tbRequiredDocFormat.Rows[requiredDocCount].Cells[1].HorizontalAlign = HorizontalAlign.Left;
this._tbRequiredDocFormat.Rows[requiredDocCount].Cells[1].VerticalAlign = VerticalAlign.Middle;
this._tbRequiredDocFormat.Rows[requiredDocCount].Cells[2].HorizontalAlign = HorizontalAlign.Left;
this._tbRequiredDocFormat.Rows[requiredDocCount].Cells[2].VerticalAlign = VerticalAlign.Middle;

尽管所有的尝试,我不能让细胞更接近。我希望桌子在中心,细胞彼此靠近,以便它看起来更好。请提出解决方案。

1 个答案:

答案 0 :(得分:1)

看起来您的表格使用了100%的可用宽度,因此您可能希望减少它,即:_tbRequiredDocFormat.Width = 400。检查你的CSS是不是应用了导致这种情况的一些样式。如果那不是解决方案可以发布原始html?

要对齐表格,请添加样式:margin: 0px auto;但由于这是您正在构建的控件,因此您必须创建一个CCS类并调用它,例如:_tbRequiredDocFormat.CssClass = "CenterTable";