Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8838035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:53:07+00:00 2026-06-14T09:53:07+00:00

So I’ve been looking around for a good answer to this question, but haven’t

  • 0

So I’ve been looking around for a good answer to this question, but haven’t really found anything useful. Hopefully someone can shed some light on this for me.

Basically, I have a repeater that is backed by a database table. Inside the ItemTemplate for this repeater, I have some HTML elements that are populated with properties from each item in the list. Pretty standard stuff. However, there is a possibility that one of the items could be null. In that case, it would make sense for me to put some sort of if (blah != null) logic around the offending code. The only problem is, when I’ve tried to do so, ASP throws up on me, telling me that I can’t use an if statement inside of <%# %>.

My question to the masses is this: if you can’t use an if statement inside of <%# %>, then how are you supposed to do conditional logic based on the values of each item?

I know that you can call your own methods inside the repeater, but that won’t work for what I’m trying to do.

Below is what I’m trying to accomplish, to better illustrate my point.

<asp:Repeater runat="server" ID="repeater">
    <ItemTemplate>
        <div class="item-wrap">
            <% if(Eval("imageUrl") != null) { %>
            <div class="plan-img">
                <asp:Image runat="server" ImageUrl='<%# Eval("imageUrl") %>'/>
            </div>
            <% } %>
        </div>
    </ItemTemplate>
</asp:Repeater>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:53:09+00:00Added an answer on June 14, 2026 at 9:53 am

    inside your ItemTemplate write the markup like this:

    <asp:Panel runat="server" Visible='<%# Eval("imageUrl") != null %>'>
        <asp:Image runat="server" ImageUrl='<%# Eval("imageUrl") %>'/>
    </asp:Panel>
    

    Basically you can’t mix code <% with databinding constructs <%#.

    My advice would be to add the following property in your CodeBehind:

        protected YourClass DataItem
        {
            get
            {
                return (YourClass)this.Page.GetDataItem();
            }
        }
    

    and then write the markup without Eval():

        <asp:Image runat="server" ImageUrl='<%# DataItem.imageUrl %>'/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.