0
<ajax:Rating ID="rating" runat="server" MaxRating="5" CurrentRating="3.2" 
CssClass="rstar" StarCssClass="ritem" WaitingStarCssClass="svd" 
FilledStarCssClass="fld" EmptyStarCssClass="empt"  AutoPostBack="True" 

get me error:

Cannot create an object of type 'System.Int32' from its string representation '3.2' for the 'CurrentRating' property.

C# code:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Rating(rating.CurrentRating);
            }
          }

 private void Rating(double value)
        {
            Label1.Text = "Selected value  " + EvalRating(value, rating.MaxRating, rt_min, rt_max);
        }

        private static string EvalRating(double value, int maxvalue, int minrange, int maxrange)
        {
            int stepDelta = (minrange == 0) ? 1 : 0;
            double delta = (double)(maxrange - minrange) / (maxvalue - 1);
            double result = delta * value - delta * stepDelta;
            return FormatRes(result);
        }

        private static string FormatRes(double value)
        {
            return String.Format("{0:g}", value);
        }

        protected void rating_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)
        {
            Rating(int.Parse(e.Value));
        }
senzacionale
  • 20,448
  • 67
  • 204
  • 316

1 Answers1

4

"3.2" isn't an int value, but a double. Try changing the rating_Changed logic to:

Rating(double.Parse(e.Value));
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • thx for such a fast help but i still get Cannot create an object of type 'System.Int32' from its string representation '3.2' for the 'CurrentRating' property. – senzacionale Feb 15 '11 at 20:56
  • @senzacionale: What line gives you that error message, now? This was the only integer conversion in the code you displayed... – Reed Copsey Feb 15 '11 at 21:34
  • @senzacionale: You didn't post that code - but make sure "CurrentRating" is a **double**, not an int. – Reed Copsey Feb 15 '11 at 21:48
  • @senzacionale See comment to your question. I'm not familiar with AJAX and maybe it's silly, but in C# you have `Rating(rating.CurrentRating);`. So what class does `rating` object instantiate and where from it knows what is `CurrentRating`? – Ilya Dvorovoy Feb 16 '11 at 06:02