468,554 Members | 1,332 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

Single and Double Quotes in ASP.NET

Hi Everyone,

I have a DataGrid which contains various columns, one of which is an
image which comes from the data source. I'd like to bind the HTML
'alt' setting as well with text from the data source. A problem occurs
when the text in the data source has a single quote however.

For example, if the text in the data source is "John Doe's tractor",
only "John Doe" appears in the IMG tag. (The single quote terminated
the string.)

My code is below. I've played around with rearranging the quotes, but
no success. Does anyone know a way around this? (Incidentally, I even
tried changing "John Doe's" in my data source to John Doe's but
the result is the same.)

<ItemTemplate>

<IMG alt='<%# DataBinder.Eval(Container.DataItem, "Description")%>'
src='<%# "thumbs/" + DataBinder.Eval(Container.DataItem,
"Snapshot")%>' width="100px">

</ItemTemplate>

Thanks,
Roger

Nov 18 '05 #1
3 9858
Roger,

Try <IMG alt="<%# DataBinder.Eval(Container.DataItem, \"Description\")%>"

Eliyahu

"Roger Helliwell" <rh********@telus.net> wrote in message
news:d6********************************@4ax.com...
Hi Everyone,

I have a DataGrid which contains various columns, one of which is an
image which comes from the data source. I'd like to bind the HTML
'alt' setting as well with text from the data source. A problem occurs
when the text in the data source has a single quote however.

For example, if the text in the data source is "John Doe's tractor",
only "John Doe" appears in the IMG tag. (The single quote terminated
the string.)

My code is below. I've played around with rearranging the quotes, but
no success. Does anyone know a way around this? (Incidentally, I even
tried changing "John Doe's" in my data source to John Doe&apos;s but
the result is the same.)

<ItemTemplate>

<IMG alt='<%# DataBinder.Eval(Container.DataItem, "Description")%>'
src='<%# "thumbs/" + DataBinder.Eval(Container.DataItem,
"Snapshot")%>' width="100px">

</ItemTemplate>

Thanks,
Roger

Nov 18 '05 #2
Jos
Roger Helliwell wrote:
Hi Everyone,

I have a DataGrid which contains various columns, one of which is an
image which comes from the data source. I'd like to bind the HTML
'alt' setting as well with text from the data source. A problem occurs
when the text in the data source has a single quote however.

For example, if the text in the data source is "John Doe's tractor",
only "John Doe" appears in the IMG tag. (The single quote terminated
the string.)

My code is below. I've played around with rearranging the quotes, but
no success. Does anyone know a way around this? (Incidentally, I even
tried changing "John Doe's" in my data source to John Doe&apos;s but
the result is the same.)

<ItemTemplate>

<IMG alt='<%# DataBinder.Eval(Container.DataItem, "Description")%>'
src='<%# "thumbs/" + DataBinder.Eval(Container.DataItem,
"Snapshot")%>' width="100px">

</ItemTemplate>

Thanks,
Roger


Replace every single quote with &apos; on databinding:
<%# Replace(DataBinder.Eval(Container.DataItem,
"Description"),"'","&apos;")%>

--

Jos

Nov 18 '05 #3
On Mon, 5 Jul 2004 09:40:25 +0200 in
microsoft.public.dotnet.framework.aspnet, "Jos"
<jo***************@fastmail.fm> wrote:
Replace every single quote with &apos; on databinding:
<%# Replace(DataBinder.Eval(Container.DataItem,
"Description"),"'","&apos;")%>


Makes sense in theory, but since I'm enclosing everything within
single quotes, the "'" string still causes a syntax error.
I did finally work out a solution though, although it's a hack. In my
Page_Load event, I iterate through all rows in my DataSet and replace
every single quote with "&rsquo;" (That's the right-angled single
quote). It seems the <img alt> attribute doesn't seem to mind that.

Roger

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by sinister | last post: by
11 posts views Thread by Jakanapes | last post: by
4 posts views Thread by sankofa | last post: by
5 posts views Thread by Joel | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.