【问题标题】:asp.net inline tags within a table cell表格单元格中的 asp.net 内联标签
【发布时间】:2012-07-18 16:57:59
【问题描述】:

使用内联语法时,我无法正确显示“样式宽度”值。它呈现为:

style=""

任何建议。

<table>
    <tr id="tr1" runat="server">
        <td style="width: <%= this.LabelColumnWidth %>">
            &nbsp;
        </td>
    </tr>
</table>

【问题讨论】:

  • 你从哪里拉宽度?是来自另一个 asp.net 控件还是来自后面的代码?
  • @Robert 请给我们看完整的代码

标签: asp.net syntax styles inline


【解决方案1】:

试一试

<td style="width: <%# this.LabelColumnWidth %>">

编辑:(现在我知道的更多了)

你为什么不给 td 添加一个 id 这样的东西

 <td id="test" runat="server">

然后在代码后面做

 test.style = "width: 100px;" // or whatever

【讨论】:

  • 不,我通常使用&lt;%# 而不是&lt;%=.. 虽然我不确定有什么区别。
  • 谢谢,我试图避免将它们转换为服务器控件。但这可能是唯一的方法。
【解决方案2】:

内联尝试 2:

试一试

<td style='<%# "width: " + this.LabelColumnWidth %>'>

想也许整个事情都需要在内联代码中。而不仅仅是宽度的值。

【讨论】:

    【解决方案3】:

    Eric 建议的答案几乎是正确的。只是,它应该有一个 = 而不是 #

    <td style='<%= "width:" + this.LabelColumnWidth %>' > 
    

    仅当您需要包含 eval() 或 bind() 函数时才使用哈希。否则,请使用 = 符号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多