How to use HtmlEncode with TemplateFields, Data Binding, and a GridView

后端 未结 9 2139
借酒劲吻你
借酒劲吻你 2020-12-13 18:51

I have a GridView bound to an ObjectDataSource. I\'ve got it supporting editing as well, which works just fine. However, I\'d like to safely HtmlEncode text that is displa

9条回答
  •  借酒劲吻你
    2020-12-13 19:38

    This is now possible to do using the new HTML encoding databinding syntax introduced in ASP.NET 4.

    You can simply use:

    <%#: Eval("MyField") %>
    

    Or

    <%#: Bind("MyField") %>
    

    Note the colon after the pound/hash sign It's as simple as that.

提交回复
热议问题