Web Hosting Talk







View Full Version : (ASP.NET) Displaying a rating/number as an image (e.g. 4 or 5 stars)


boomers
02-20-2006, 06:14 PM
Hello... another problem that is perplexing me

Again I am making a website... on this site you can rate someone/something with score of 1 - 5 which is then included in the sum for the total average & stored in a database.

You can also view someone else's total average rating... all ive done here is run an sql query to get the number from the database and display it via a label.

"SELECT average FROM rating WHERE blah blah"

and then...
If myDataReader.Read() Then
Me.lblRating.Text = "Overall average score is " & myDataReader("rating")

So you would see something like: "Overall average score is 4"

- What I would like to know is how I can show a picture of 4 stars show instead of the number '4'.

Please can someone give an example... say if I had 5 seperate .gif images of stars:
1star.gif
2star.gif
3star.gif
4star.gif
5star.gif

I would really appreciate anyones help.

lvmike
02-20-2006, 08:27 PM
Try this. Create an image tag in the page, just after your text lable, and set it to run at the server

<img id="imgRating" runat="server" />

then in your codebehind set the image src path.

imgRating.Src = myDataReader("rating") & "star.gif"

Padwah
02-21-2006, 06:37 AM
Rather than having 5 different star images just have one and create a loop to add the stars. i.e:

If myDataReader.Read() Then
Me.lblRating.Text = "Overall average score is "


do until intStars = myDataReader("Rating")

Me.lblRating.Text &= "<img src='star.gif' alt='star' title='"& intStars &' />"

intStars += 1

loop