I am making i site where people can make reviews of movies and when they make the review they need to put a rating to a movie, in a number of 1 to 5.
But when it print out on another page I want to print out stars insted of the number 3 for exemple.
For now I got this code:
StringBuilder movielistSB = new StringBuilder();
foreach (var moviereview in movielistSB)
{
filmanmeldelserlisteSB.AppendFormat(
"<div id='moviereview'><artitcle><h3>{0}</h3>" +
"<table><tr><td>ID:</td><td>{1}</td></tr>" +
"<tr><td>Anmeldelse:</td><td>{2}</td></tr>" +
"<tr><td>Rating:</td><td>{3}</td></tr></table></article></div>",
(string)moviereview.Element("title"),
(string)moviereview.Element("id"),
(string)moviereview.Element("review"),
(string)moviereview.Element("rating")
);
And for the (string)moviereview.Element("rating") I want to print out for exempel 3 stars when a user has given the movie a rating of 3.
I tried to run a for loop, but I could not figur out how to get that to work. And I've tried to Google for a solution, but anyhow I can't get it to work.
Any ideas?
EDIT: For now I got this:
String star = @"<img src=""../images/star.png""/>";
if (moviereviewlist.Count() > 0)
{
StringBuilder moviereviewlistSB = new StringBuilder();
foreach (var moviereview in moviereviewlist)
{
filmanmeldelserlisteSB.AppendFormat(
"<div id='moviereview'><artitcle><h3>{0}</h3>" +
"<table><tr><td>ID:</td><td>{1}</td></tr>" +
"<tr><td>Review:</td><td>{2}</td></tr>" +
"<tr><td>Rating:</td><td>{3}</td></tr></table></article></div>",
(string)moviereview.Element("tittel"),
(string)moviereview.Element("id"),
(string)moviereview.Element("anmeldelse"),
star.RepeatString((int)moviereview.Element("rating"))
);
and this
public static class StringExtensions
{
public static string RepeatString(this string input, int count)
{
if (!string.IsNullOrEmpty(input))
{
return string.Empty;
}
StringBuilder builder = new StringBuilder(input.Length * count);
for(int i = 0; i < count; ++i)
{
builder.Append(input);
}
return builder.ToString();
}
}
I had to parse the `(int)filmanmeldelse.Element("rating")' to an int. But for somehow I can't get a image on the site. Its only blank and I have tried different ways, but It will not get a value to the site.