#region 实现降序排序
class NameDESC : IComparer<Student>
{
public int Compare(Student x, Student y)
{
return y.StudentName.CompareTo(x.StudentName);
}
}
class StudentDESC : IComparer<Student>
{
public int Compare(Student x, Student y)
{
return y.StudentId.CompareTo(x.StudentId);
}
}
#endregion
//姓名降序
private void btnNameDESC_Click(object sender, EventArgs e)
{
if (this.dgvStudentList.RowCount == 0) return;
this.stuList.Sort(new NameDESC());
this.dgvStudentList.Refresh();
}
//学号降序
private void btnStuIdDESC_Click(object sender, EventArgs e)
{
if (this.dgvStudentList.RowCount == 0) return;
this.stuList.Sort(new StudentDESC());
this.dgvStudentList.Refresh();
}
this.dgvStudentList.AutoGenerateColumns = false;//禁止自动生成列
//执行查询并绑定数据
this.stuList= objStudentService.GetStudentByClass(this.cboClass.Text);
this.dgvStudentList.DataSource = this.stuList;
new Common.DataGridViewStyle().DgvStyle1(this.dgvStudentList);