<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:
Не удается создать объект типа 'System.Int32' из его строкового представления '3.2' для свойства CurrentRating. C # код: 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)); }
Не удается создать объект типа 'System.Int32' из его строкового представления '3.2' для свойства CurrentRating.
C # код:
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)); }
«3.2» - это не значение типа int, а double. Попробуйте изменить логику rating_Changed на:
rating_Changed
Rating(double.Parse(e.Value));