本文介绍了如何使用类结构将数据发布到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误在于:
The error is with:
highscores[0] = new Percentage("098", "2014/02/01", "78");
highscores[1] = new Percentage("078", "2014/05/15", "68");
highscores[2] = new Percentage("045", "2014/09/16", "71");
代码:
Code:
public class Percentage
{
public string id { get; set; }
public string DateTime { get; set; }
public string Percent { get; set; }
}
protected void btn2(object sender, EventArgs e)
{
Percentage[] highscores = new Percentage[3];
highscores[0] = new Percentage("098", "2014/02/01", "78");
highscores[1] = new Percentage("078", "2014/05/15", "68");
highscores[2] = new Percentage("045", "2014/09/16", "71");
highscores = highscores.OrderByDescending(s => s.Percent).ToArray();
GridView1.DataSource = highscores;
GridView1.DataBind();
}
错误代码:
Error code:
'theScore._Default.Percentage' does not contain a constructor that takes 3 arguments C:\Users\user\path\Default.aspx.cs
推荐答案
protected void btn2(object sender, EventArgs e)
{
List<percentage> objPercentage = new List<percentage>();
objPercentage.Add(new Percentage{ id="098", DateTime="2014/02/0", Percent="78"});
objPercentage.Add(new Percentage{ id="099", DateTime="2014/02/0", Percent="68"});
objPercentage.Add(new Percentage{ id="099", DateTime="2014/02/0", Percent="68"});
GridView1.DataSource = objPercentage;
GridView1.DataBind();
}
这篇关于如何使用类结构将数据发布到gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!