【问题标题】:How to change td content dynamically?如何动态更改 td 内容?
【发布时间】:2009-11-04 21:45:52
【问题描述】:

我必须根据复选框动态更改 td 内容。如果未选中复选框,则 td 不会采用额外的样式,但如果选中,我的文本必须采用这样的样式:

b style="font-family:Tahoma;font-size:8pt;color:#0f0000;font-weight:normal;">My Text</b

Mycode 是这样的:

asp:DataList ID="Inside" runat="server" RepeatColumns="4"

ItemTemplate

  <asp:HiddenField ID="FeaID2" runat="server" Value='<%#DataBinder.Eval(Container.DataItem, "FeatureID")%>' >

    <td class="checkbox_td"><input disabled="disabled" type="checkbox" <%# int.Parse(DataBinder.Eval(Container.DataItem, "exist").ToString()) > 0 ? "checked" : "" %> /></td>

    <td class="text_td">!!!HERE IS MY PROBLEM!!!</td>

/ItemTemplate

/asp:DataList

我使用 C#,那么,我如何动态地为我调用的 td 内容赋予额外的样式(这是我的问题),这取决于下面的复选框?

【问题讨论】:

    标签: c# asp.net html


    【解决方案1】:

    为你的 CSS 添加另一个选择器:-

    td.text_td_checked { font-family:Tahoma;font-size:8pt;color:#0f0000;font-weight:normal; }
    

    确保它位于 CSS 中的 text_td 选择器之后。在你的 TD 中:-

    <td class="text_td <%# int.Parse(DataBinder.Eval(Container.DataItem, "exist").ToString()) > 0 ? "text_td_checked" : "" %>">!!!Problem Solved!!!</td>
    

    【讨论】:

    • 谢谢安东尼,这很容易,不是吗? :) 我必须学到很多东西:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    • 1970-01-01
    相关资源
    最近更新 更多