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,
RogerRoger,
Try <IMG alt="<%# DataBinder.Eval(Container.DataItem, \"Description\")%>"
Eliyahu
"Roger Helliwell" <rhelliwell@.telus.net> wrote in message
news:d6ohe0pvnbeq61crh9tpfsffr5n11ihvj3@.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'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
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'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 ' on databinding:
<%# Replace(DataBinder.Eval(Container.DataItem,
"Description"),"'","'")%
--
Jos
On Mon, 5 Jul 2004 09:40:25 +0200 in
microsoft.public.dotnet.framework.aspnet, "Jos"
<josnospambranders@.fastmail.fm> wrote:
>Replace every single quote with ' on databinding:
><%# Replace(DataBinder.Eval(Container.DataItem,
>"Description"),"'","'")%
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 "’" (That's the right-angled single
quote). It seems the <img alt> attribute doesn't seem to mind that.
Roger
0 comments:
Post a Comment