首页 新闻 会员 周边 捐助

“_Default.Student”不包含采用“3”参数的构造函数

-1
[已关闭问题] 关闭于 2012-07-21 23:49

 public static List<Student> Students = new List<Student>();
    public static int i = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.IsPostBack == false)
        {
            Students.Add(new Student("张三", "男", "11"));
            Students.Add(new Student("李四", "男", "22"));
            Students.Add(new Student("王五", "女", "33"));
            DataBind();
        }
    }
    public class Student
    {
        private string name;
        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        private string sex;
        public string Sex
        {
            get { return this.name; }
            set { this.sex = value; }
        }

        private int age;
        public int Age
        {
            get { return this.age; }
            set { this.age = value; }
        }

      
    }
    protected void btnPrev_Click(object sender, EventArgs e)
    {
        if (i > 0)
        {
            i--;
            DataBind();
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (i < Students.Count - 1)
        {
            i++;
            DataBind();
        }
    }

doubledu的主页 doubledu | 初学一级 | 园豆:199
提问于:2011-11-25 21:29
< >
分享
所有回答(3)
0

DataBind();方法是怎么写的呢

artwl | 园豆:16736 (专家六级) | 2011-11-25 21:34

Student类改为:

public class Student
{
public Student(string _name,string _sex,int _age)
{
this.name=_name;
this.sex=_sex;
this.age=_age;
}

private string name;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
private string sex;
public string Sex
{
get { return this.name; }
set { this.sex = value; }
}
private int age;
public int Age
{
get { return this.age; }
set { this.age = value; }
}
}

或把Page_Load内代码改为:

    protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack == false)
{
Students.Add(new Student(){Name="张三", Sex="",Age= 11});
Students.Add(new Student(){Name="李四", Sex="",Age= 22});
Students.Add(new Student(){Name="王五", Sex="",Age=33});
DataBind();
}
}




支持(0) 反对(0) artwl | 园豆:16736 (专家六级) | 2011-11-25 22:00

@artwl:  为什么又会出现  不包含采用“0”参数的构造函数 呢?  高手,求解!

支持(0) 反对(0) doubledu | 园豆:199 (初学一级) | 2011-11-25 22:44

@彼耶: 哥们儿,上面两段代码只改一处,是“

支持(0) 反对(0) artwl | 园豆:16736 (专家六级) | 2011-11-25 22:46
0

你的 Students.Add(new Student("张三", "男", "11")); 很明显的表明你没有这个构造函数

小小刀 | 园豆:1991 (小虾三级) | 2011-11-25 21:54
1

Student类里面必须有一个

public Student(){}

的构造方法。

ojdev | 园豆:205 (菜鸟二级) | 2011-11-26 00:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册