<ajax:Rating ID="rating" runat="server" MaxRating="5" CurrentRating="3.2"
CssClass="rstar" StarCssClass="ritem" WaitingStarCssClass="svd"
FilledStarCssClass="fld" EmptyStarCssClass="empt" AutoPostBack="True"
误会我:
无法创建类型的对象 来自其字符串的'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));
}
答案 0 :(得分:4)
“3.2”不是int值,而是double。尝试将rating_Changed
逻辑更改为:
Rating(double.Parse(e.Value));