PC Review


Reply
Thread Tools Rate Thread

Condition on Container.DataItem in inline code

 
 
az bij
Guest
Posts: n/a
 
      29th Jul 2004
Hi,

I have a dataset bound to a repeater and want to place some logic in
my ascx file. I want to display an image link if and only if an image
is available.

I have tried without success variations of:

<%#if(DataBinder.Eval(Container.DataItem,"ImageFilename"!="")){%>
<a href="#"><img src=<%#DataBinder.Eval(Container.DataItem,
"ImageFilename")%>/></a>
<%}%>


The above gives: Compiler Error Message: CS1513: } expected

Replacing the last <%}%> with <%#}%> gives: CS1525: Invalid expression
term 'if'
And if I remove the # from the first directive: CS0246: The type or
namespace name 'Container' could not be found

It's driving me mad. Can anyone help please?

Thanks,
Andy
 
Reply With Quote
 
 
 
 
Neil Woodvine
Guest
Posts: n/a
 
      30th Jul 2004

Have not used the Repeater before, but for DataBinding statement in DataGrid
and DataList you need to use the IIF statement for conditional processing.

e.g.
iif(DataBinder.Eval(Container.DataItem, "ImageFilename") = "", "", "<a href
..... etc")

Also, note position of first closing parenthesis. You need to resolve the
DataBinder.Eval statement before testing it against the empty string.

Cheers,
Neil


"az bij" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I have a dataset bound to a repeater and want to place some logic in
> my ascx file. I want to display an image link if and only if an image
> is available.
>
> I have tried without success variations of:
>
> <%#if(DataBinder.Eval(Container.DataItem,"ImageFilename"!="")){%>
> <a href="#"><img src=<%#DataBinder.Eval(Container.DataItem,
> "ImageFilename")%>/></a>
> <%}%>
>
>
> The above gives: Compiler Error Message: CS1513: } expected
>
> Replacing the last <%}%> with <%#}%> gives: CS1525: Invalid expression
> term 'if'
> And if I remove the # from the first directive: CS0246: The type or
> namespace name 'Container' could not be found
>
> It's driving me mad. Can anyone help please?
>
> Thanks,
> Andy



 
Reply With Quote
 
az bij
Guest
Posts: n/a
 
      2nd Aug 2004
Thanks a lot Neil.

got there in the end..

<%# ((DataBinder.Eval(Container.DataItem,
"ImageFilename").ToString()=="") ? "" :"<a
href="+DataBinder.Eval(Container.DataItem, "link")+"><img
src='/Images/Products/"+DataBinder.Eval(Container.DataItem,
"ImageFilename")+"' border='0' /></a>")%>


"Neil Woodvine" <(E-Mail Removed)> wrote in message news:<cedr2d$chr$(E-Mail Removed)>...
> Have not used the Repeater before, but for DataBinding statement in DataGrid
> and DataList you need to use the IIF statement for conditional processing.
>
> e.g.
> iif(DataBinder.Eval(Container.DataItem, "ImageFilename") = "", "", "<a href
> .... etc")
>
> Also, note position of first closing parenthesis. You need to resolve the
> DataBinder.Eval statement before testing it against the empty string.
>
> Cheers,
> Neil
>
>
> "az bij" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > I have a dataset bound to a repeater and want to place some logic in
> > my ascx file. I want to display an image link if and only if an image
> > is available.
> >
> > I have tried without success variations of:
> >
> > <%#if(DataBinder.Eval(Container.DataItem,"ImageFilename"!="")){%>
> > <a href="#"><img src=<%#DataBinder.Eval(Container.DataItem,
> > "ImageFilename")%>/></a>
> > <%}%>
> >
> >
> > The above gives: Compiler Error Message: CS1513: } expected
> >
> > Replacing the last <%}%> with <%#}%> gives: CS1525: Invalid expression
> > term 'if'
> > And if I remove the # from the first directive: CS0246: The type or
> > namespace name 'Container' could not be found
> >
> > It's driving me mad. Can anyone help please?
> >
> > Thanks,
> > Andy

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Container.DataItem rn5a@rediffmail.com Microsoft ASP .NET 6 24th Sep 2007 06:49 PM
<%# ((DataBinder.Eval(Container.DataItem, "SourceAddress").ToString().ToLowerInvariant() != Rd.UserAddress.ToLowerInvariant()) ? "" : "<a href='AddRelationNote.aspx?Id=" + DataBinder.Eval(Container.DataItem, " savisss@gmail.com Windows XP Internet Explorer 0 12th Mar 2007 02:27 PM
Container.DataItem rn5a@rediffmail.com Microsoft ASP .NET 4 1st Oct 2006 10:46 AM
Container.DataItem Mike P Microsoft C# .NET 1 21st Mar 2005 02:46 AM
Adding Logic including Container.DataItem in the HTML code of DataGrid?? Lars Netzel Microsoft ASP .NET 1 14th May 2004 04:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 AM.