创建一个报名表

核心代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 学生人数 : System.Web.UI.Page
{
    Pupuil a;
    Junior b;
    Undergraduate c;
    //Student[] SG = new Student[100];
    public static int sum = 0;
    public static int sp = 0;
    public static int sj = 0;
    public static int su = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        ddl_pycc.Items.Insert(0, new Listltem("--请选择:--", ""));
        string name = TextBox1.Text;
        string sex = TextBox2.Text;
        int age = Convert.ToInt32(TextBox3.Text);
        int index = RadioButtonList1.SelectedIndex;
        a = new Pupuil();
        b = new Junior();
        c = new Undergraduate();
        if (index == 0)
        {
            sp++;
        }
        else if (index == 1)
        {
            sj++;
        }
        else
        {
            su++;
        }
        sum = sp + sj + su;
        Label1.Text = "报名成功!";
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Label2.Text = "";
        Label2.Text += "小学生人数:" + sp + "<br/>中学生人数:" + sj + "<br/>大学生人数:" + su + "<br/>总人数:" + sum;
    }
}
public abstract class Student
{
    private string name;
    public string Name
    {
        set { name = value; }
    }
    private string sex;
    public string Sex
    {
        set { sex = value; }
    }
    private int age;
    public int Age
    {
        get { return age; }
        set
        {
            if (value < 0)
                Console.WriteLine("警告:填写年龄必须大于零!");
            else
                age = value;
        }
    }
    //public abstract string sum();
}
class Pupuil : Student
{
    //public  Pupuil(string name,bool sex,int age):base(name,sex,age){}
   /* public override string sum()
    {
        return "sum";
    }*/
}
class Junior : Student
{

}
class Undergraduate : Student
{

}

实验截图:
创建一个报名表_第1张图片
创建一个报名表_第2张图片
创建一个报名表_第3张图片

你可能感兴趣的:(ASP.NET)