【问题标题】:ASP.NET: GRIDVIEW: How to strikeout the entire text in a rowASP.NET:GRIDVIEW:如何删除一行中的整个文本
【发布时间】:2009-02-11 07:25:36
【问题描述】:

我需要在 GridView 的 RowDataBound 事件中连续删除整个文本(甚至是文本/单元格之间的空白)。 有可能吗?

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    C#

    关于 RowDataBound 事件

    e.Row.Style.Value = "text-decoration:line-through;"
    

    这就是你的 GridView 的渲染方式,它可以工作!

    <table>
    <tr style="text-decoration:line-through;">
    <td>some text</td>
    <td>some text</td>
    </tr>
    <tr style="text-decoration:line-through;">
    <td>some text</td>
    <td>some text</td>
    </tr>
    <tr style="text-decoration:line-through;">
    <td>some text</td>
    <td>some text</td>
    </tr>
    </table>
    

    【讨论】:

    • 对我不起作用,也许其他一些风格会覆盖它,我不确定。
    • 你可以使用firebug来查看样式是否被覆盖,但是由于这个样式是内联的,它应该有优先级
    • 我可以使用开发人员工具栏看到该行应用的样式,但它只是无法正常工作!!
    • 感谢您的努力,但这仍然不会删除行中的整个文本(甚至是文本/单元格之间的空白)。
    • 我也试过这个 - e.Row.Font.Strikeout = true;但即使这样也行不通!
    【解决方案2】:

    是的,您可以将所有行单元格的内容放入 标记中。例如,

    row.Cell[0].Text = "<strike>cell content from row.DataItem</strike>";
    

    但它只会打击单元格中的文本。如果您为该行的表格设置了 cellpadding 和 cellspacing,那么它现在可能看起来不错。

    【讨论】:

    • 这只是删除单元格中的文本,我想删除整行,甚至是文本/单元格之间的空白。
    • 那些空白是因为单元格间距、单元格填充或应用于表格的边距。如果可能,请发送您的 GridView 的 HTML sn-p。
    【解决方案3】:
    function oprt_OnRowDataBound(e) {
        if (e.dataItem.IsDeleted == true) {
            e.row.style.textDecorationLineThrough = true;
        };
    }
    

    【讨论】:

      【解决方案4】:

      或者简单地在网格视图的 RowDataBound 事件中写入下面的颜色,它会在网格视图中删除整行

      If DataBinder.Eval(e.Row.DataItem, "Notes") <> "" Then
                      e.Row.ForeColor = Color.Red
                      e.Row.Font.Strikeout = True
      End If
      

      它对我来说很好用

      【讨论】:

        猜你喜欢
        • 2021-06-20
        • 1970-01-01
        • 2016-10-22
        • 2023-01-03
        • 1970-01-01
        • 2022-12-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多