Special (or foreign countries) characters

有些话、适合烂在心里 提交于 2019-12-10 09:42:14

问题


I am new to C# and was experimenting with the ASP.Net GridView (framework 3.5), and I found out a big problem when the gridView text contains the following:

ñ/Ñ/á/Á/é/É/í/Í/ó/Ó/ú/Ú or a â, ê, î, ô, û, ë, ï, ü or even a ç

The results end up displaying something like this: &+#+237

I made a mixture of pain by doing a table,dataset etc... to get the data from the database clean as the letter itself. I also tried making a method that cleaned the variables but it was a terrible IF.

I was wondering if there was a way to make the letters appear as themselves (ñ as ñ not as &+#+237) when extracting data from the gridview without getting the data directly from the database and without doing a lot of code. If there is not, is there a way to code efficiently clean them up?


回答1:


Your characters are being HTML encoded, either somewhere in your data access layer, or within the gridview controls. Try running the text through HttpUtility.HtmlDecode() before binding the grid.

If that doesn't work, then it's probably being encoded at the control level. I see that you tagged this question with "textbox". The standard ASP.NET TextBox control will automatically encode anything that's assigned to its Text property. Instead, you can use a generic System.Web.UI.HtmlControls.HtmlTextArea control or new HtmlGenericControl("input").



来源:https://stackoverflow.com/questions/11652928/special-or-foreign-countries-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!