skip to Main Content

I have a GridView control. Each row has a textbox with a description I need. When I pull back the description I see that the (") has been encoded:

TextBox selectedRowTextbox = (TextBox)selectedRow.Cells[5].Controls[1];
string selectedRowText = selectedRowTextbox.Text;

The result:

24" Sparkle Disco Ball

I have tried:

  • Server.HtmlDecode
  • Regex.Unescape
  • Uri.UnescapeDataString
  • Regex.Replace

What I would expect is this:

24" Sparkle Disco Ball

Any help would be greatly appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    I figured out what I was doing wrong. Visual Studio displays string values containing double quotes and backslashes like this in my example. That's not a great thing to do IMHO.


  2. You can use the HttpUtility.HtmlDecode method to decode the text.

    TextBox selectedRowTextbox = (TextBox)selectedRow.Cells[5].Controls[1];
    string selectedRowText = HttpUtility.HtmlDecode(selectedRowTextbox.Text);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search