Griview cells Text Special Characters

J

john

When I get a Gridview Cell contents that has a Special Character in its data
such as an & or " it returns it constant & or " instead of the
actual Character.



Any way to modify this code to get the actual Character as it is displayed
in the cell?



Sample cell actual text: A & C Hauling



dim ven as String

ven = me.Gridview1.SelectedRow.Cells(2).Text



Result to ven variable is A & Hauling



Thanks

John
 
P

Phil H

John

I take it that the code is in response to the "selected-index_changed"
event (Y/N?)

If so then you need to retrieve the data from the original data source
rather than the content of grid cells. The easiest way is to obtain
the record's primary key value and query the source programatically.
 
J

john

Actually I am pulling the cell contents into a formview from the already
selected record, but I think considering the few special Characters I would
to just do replace on the cell data than have to pull from the datasource
all over again.

I was hoping there was a simple way to convert or cast it from its constant.

Thanks for your reply.
 
S

Steven Cheng[MSFT]

Hi John,

For the character formatting, are you using the default "BoundField"? If
so, gridview's boundfield will perform html encoding on boundfield
content(when set via databinding) so as to avoid some potential malicious
injected script code:

#BoundField.HtmlEncode Property
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfiel
d.htmlencode.aspx

You can try turn it off if you're sure the characters in the content is
safe and non characters in it will bread page's html source(e.g it doesn't
contain chars like '<', '>'....).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.





--------------------
 
M

marss

Any way to modify this code to get the actual Character as it is displayed
in the cell?

Sample cell actual text: A & C Hauling

dim ven as String

ven = me.Gridview1.SelectedRow.Cells(2).Text

Result to ven variable is A &amp; Hauling

Try this:

ven = Server.HtmlDecode(me.Gridview1.SelectedRow.Cells(2).Text)

Regards,
Mykola
http://marss.co.ua
 
J

john

Thanks for all your input, I tried setting HtmlEncode to False and that
worked. Seeing as I do not allow any editing of that cell, I take it that it
will be safe to do.

But I also want to try the latest Idea of: Server.HtmlDecode to see how that
works also for the times when I need that security.

Thanks for all your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top