开发者

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

<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 res开发者_如何学Goult = 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));
        }


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

Rating(double.Parse(e.Value));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜