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

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

    Bind() is used for Two-Way Data Binding, for this to work you will have to use the RowUpdating event of the gridview.

    void GridView_RowUpdating(Object sender, GridViewUpdateEventArgs e)
    {
        foreach (DictionaryEntry entry in e.NewValues)
        {
            e.NewValues[entry.Key] = System.Web.HttpUtility.HtmlEncode(entry.Value.ToString());
        }
    }
    

提交回复
热议问题