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

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

    In my case I was forced to use the "Bind" method on mi EditItemTemplate's TextBox because needed the data to be accessible in the NewValues array at the item_Updating event handling. So i figured out as follow:

    on my EditItemTemplate :

    
                                                     
     
    

    then in the code behind :

    protected void TextBox_PreRender_decode(object sender, EventArgs e)
    {
        TextBox tb = (TextBox)sender;
        tb.Text = WebUtility.HtmlDecode(tb.Text);
    }
    

    This solution allowed me to show properly an html-encoded data for all of my TextBoxes and at the same time being able to access this data from the newValues array when the item_Updating event fires.

提交回复
热议问题