0

I am using Listview to populate users ratings on particular item. Now I have product in which 4 people voted. But it's not showing stars filled correctly. e.g. if rating score is 4 then it filled with 5 stars. enter image description here

Listview

 <form id="form1" runat="server">
        <asp:ToolkitScriptManager ID="sc1" runat="server"></asp:ToolkitScriptManager>
    <div>
        <table class="table table-bordered">

            <tr>
                <td>Ratings</td>
                <td>Stars</td>
            </tr>
           <asp:ListView ID="lvReviews" runat="server">
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Label ID="rates" runat="server" Text='<%# Eval("ratingGiven") %>'></asp:Label>
                    </td>

                    <td>
                        <asp:Rating ID="Rating1" runat="server" ClientIDMode="Static" StarCssClass="star fa fa-star" EmptyStarCssClass="empty fa fa-star" WaitingStarCssClass="WaitingStar fa fa-star" FilledStarCssClass="FilledStar fa fa-star" MaxRating="5" CurrentRating='<%# Eval("ratingGiven") %>' ReadOnly="true">
                        </asp:Rating>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:ListView>
        </table>
    </div>
    </form>

Code Behind

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using MySql.Data.MySqlClient;
partial class ratings : System.Web.UI.Page
{

    string query;
    private void ratings_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack) {
            this.bindReviews();
        }
    }

    private void bindReviews()
    {
        try {
            query = "SELECT * FROM reviews WHERE status = 'active' and productID = @productID ORDER BY ID DESC";
            string conString = ConfigurationManager.ConnectionStrings("conio2").ConnectionString;
            MySqlConnection con = new MySqlConnection(conString);
            MySqlCommand cmd = new MySqlCommand(query);
            cmd.Parameters.AddWithValue("@productID", "1111");
            con.Open();
            MySqlDataAdapter da = new MySqlDataAdapter();
            cmd.Connection = con;
            da.SelectCommand = cmd;
            DataTable dt = new DataTable();
            da.Fill(dt);
            ViewState("Data") = dt;
            lvReviews.DataSource = dt;
            lvReviews.DataBind();
            con.Close();
        } catch (Exception ex) {
            Response.Write(ex);
        }
    }
    public ratings()
    {
        Load += ratings_Load;
    }
}
SUN
  • 973
  • 14
  • 38
  • Is it always +1 ? – Wouter van Vegchel Jun 28 '17 at 05:42
  • From the code it should work, is there Javascript involved? And is it always the first item in the list? –  Jun 28 '17 at 05:53
  • @WoutervanVegchel I have added one more after that previous one shown correctly but latest review again had same problem. I given 3 star but it took 5 star. See this http://foxboxrewards.com/ratings.aspx that means it has prpblem only with last added rating – SUN Jun 28 '17 at 12:09

0 Answers0