views:

516

answers:

3

Hi All,

I tried to ask this question previously howver I did not recieve the correct response. I am using a GridView in the admin area of site I have designed. I use a DetailsView to insert data into the database, and the Gridview to edit and delete the data.

My query is: When I add data in the DetailsView I enter data like this: "PR Murphy & Associates" Notice the "&".

WHat is happening is that when it display the data in the gridview it displays it as "PR Murphy & Associates" however when I click the edit button it displays "PR Murphy &amp Associates". Notice the encoded & symbol.

My problem is that I don't want the code to htmlencode the & symbol at all. I am fairly new to ASP.NET and am not sure how to achieve this goal.

IE Is the DetailsView encoding the string when it inserts the data into the database. What code could I use to stop this from happening and what event would I need to target.

In my previous response it was suggested that I set HTMLEncode="False" in the gridview. I have tried that with a bound field and it did not make a difference. Also I need this field to be as a TemplateField in the GridView so that I can perform some error handling on the entries.

I hope this makes sense and someone can please guide me in the right directions.

Thanks

A: 

I suppose you could with your template call a method that would replace the & with a & again. Since you want a TemplateField this would be the five minute fix that probably wouldn't be the best way but would work in a pinch.

Paste some of the code though so we can edit/help.

rball
A: 

If you discover that you can't change the behavior of the control to return the un-encoded value, then you might be happy to know about HtmlDecode.

Ken Browning
A: 

The value should be encoded. If your value is AT&T, your final HTML should look something like:

<input type="text" value="AT&amp;T" />

Post code and outputted HTML if that's not what you're seeing.

Mark Brackett