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

后端 未结 9 2120
借酒劲吻你
借酒劲吻你 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:39

    What about a simple extension method?

    public static string HtmlEncode(this string s)
        {            
            s = HttpUtility.HtmlEncode(s);
            return s;
        }
    

    You could then simply run:

     />
    

提交回复
热议问题