【问题标题】:How to set alignment of text in cell of a dynamically generated table in ASP?如何在 ASP 中动态生成表格的单元格中设置文本对齐方式?
【发布时间】:2017-12-06 02:00:40
【问题描述】:

我正在处理下表。是动态生成的表,

TableRow durationTableRow = new TableRow();
TableDuration.Rows.Add(durationTableRow);
for (durationCellCounter = 1; durationCellCounter <= durationCellCount; durationCellCounter++)
{
    if (durationCellCounter == 1)
    {
        TableCell durationTableCell = new TableCell();
        durationTableCell.Text = "Duration: ";
        durationTableRow.Cells.Add(durationTableCell);
    }
    else if (durationCellCounter == 2)
    {
        TableCell durationTableCell = new TableCell();
        string duration = years + "Y. " + months + "M. " + days + "D.";
        durationTableCell.Text = duration;
        durationTableRow.Cells.Add(durationTableCell);
    }
}

我想右对齐表中持续时间字符串的值。

【问题讨论】:

    标签: asp.net visual-studio html-table


    【解决方案1】:

    您可以为单元格添加对齐属性。

    durationTableCell.Attributes.Add("align", "right");
    

    或者用css

    <asp:Table ID="TableDuration" CssClass="rightAlign"></asp:Table>
    
    <style>
        .rightAlign td {
            text-align: right;
        }
    </style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-14
      • 2015-07-29
      • 1970-01-01
      • 2022-06-15
      • 2012-11-07
      • 2014-05-25
      • 2011-11-30
      • 1970-01-01
      相关资源
      最近更新 更多