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 713893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:00:46+00:00 2026-05-14T05:00:46+00:00

My datasource has an Rating dataItem contains an integer from 0 to 5. I’d

  • 0

My datasource has an Rating dataItem contains an integer from 0 to 5. I’d like to print stars accordignly.

I’m trying to do it within Repeater control:

<b>Rating:</b>

<% for (int j = 1; j <= DataBinder.Eval(Container.DataItem, "Rating"); j++)
{  %>
<img src="App_Pics/fullstar.png" />
<% }
for (int j = 1; j <= 5 - DataBinder.Eval(Container.DataItem, "Rating"); j++)
{ %>
<img src="App_Pics/emptystar.png" />
<%} %>
  1. I get the error The name 'Container' does not exist in the current context. It is weird, because when I used <%# DataBinder.Eval(Container.DataItem, "Name")%> a line before, it worked great.
  2. Is it clever to include loops in my aspx page? I think it’s not very convenient. What’s my alternatives?
  3. What’s that # means?

Thank you very much.

  • 1 1 Answer
  • 1 View
  • 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-05-14T05:00:46+00:00Added an answer on May 14, 2026 at 5:00 am

    The # indicates code to be executed when data-binding occurs (i.e. when DataBind() is called on the control or the page). The <%# %> syntax is the data-binding equivilent of <%= %> so unfortunately you can’t just wrap your loop in <%# %> blocks and be done with it.

    You can around this limitation by implementing a code-behind method and passing the rating to the method:

    <%# GetStars(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "Rating"))) %>
    

    And then implement the method as:

    protected string GetStars(int rating)
    {
        string output = string.Empty;
        for (int j = 1; j <= rating; j++) output += "<img src=\"App_Pics/fullstar.png\" />";
        for (int j = 1; j <= 5 - rating; j++) output += "<img src=\"App_Pics/emptystar.png\" />";
        return output;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.net gridview that I am trying bind to. My DataSource has
I'm trying to create a user control which has a DataSource, which can accept
If I have a control on a page that has its Datasource set to
I have a datasource that I want to bind to a listview that has
I would like to use a component that exposes the datasource property, but instead
if the parent's datasource has a child property that is a collection (let's say
I'm writing a ZenPack for Zenoss which includes a new DataSource. The DataSource has
http://developer.yahoo.com/yui/datasource/#events I'm trying to use the responseParseEvent but I don't know how to hook
I'm using a Bitwise Enum as a Datasource for a repeater control in which
Both DataSource and DataSourceID are defined on 'grdCommunication'. Remove one definition. I just got

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.