⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 student.aspx.cs

📁 本在线考试系统采用了面向对象的分析和设计
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ExaminationSystem.BLL.Service;
using ExaminationSystem.BLL.Domain;

public partial class Admin_Student : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindClassList();
            BindGridView();
        }
    }
    private void BindGridView()
    {
        Class cs = new ClassService().GetById(long.Parse(DropDownList1.SelectedValue));
        GridView1.DataSource = cs.Students;
        GridView1.DataBind();
    }
    private void BindClassList()
    {
        DropDownList1.DataSource = new ClassService().GetAll();
        DropDownList1.DataTextField = "Name";
        DropDownList1.DataValueField = "ID";
        DropDownList1.DataBind();
        if (DropDownList1.Items.Count > 0)
            DropDownList1.SelectedIndex = 0;
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        Student student = new Student();
        student.Name = TextBox1.Text;
        student.StudentID = TextBox2.Text;
        student.Password = TextBox2.Text;
        student.LoginName = TextBox2.Text;
        student.Class =GetSelectedClass();
        try
        {
            new StudentService().Save(student);
            BindGridView();
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }
    }
    private Class GetSelectedClass()
    {
        return new ClassService().GetById(long.Parse(DropDownList1.SelectedValue));
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        long id = long.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
        new StudentService().DeleteById(id);
        BindGridView();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;

        BindGridView();
        ((ASP.usercontrols_classdropdownlist_ascx)GridView1.Rows[e.NewEditIndex].Cells[2].Controls[1]).BindClass();
        ((ASP.usercontrols_classdropdownlist_ascx)GridView1.Rows[e.NewEditIndex].Cells[2].Controls[1]).SetSelectedClass(GetSelectedClass());

    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string studentId = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text;
        string name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
        Class cs = ((ASP.usercontrols_classdropdownlist_ascx)GridView1.Rows[e.RowIndex].Cells[2].Controls[1]).SelectedClass;
        long id = long.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());

        Student student = new StudentService().GetById(id);
        student.Name = name;
        student.StudentID = studentId;
        student.Class = cs;
        new StudentService().Update(student);

        GridView1.EditIndex = -1;
        BindGridView();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindGridView();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindGridView();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -