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

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

    But take care if you use following code from Phaedrus and you have a checkbox column!

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

    Because the entry.Value.ToString() will make the true from the Checkbox to True and then you can not save it in the database field!

提交回复
热议问题