C# 怎样利用下拉列表对GridView进行动态查询?
2个回答
展开全部
学三层架构吗?三层分为表示层,业务逻辑层,数据访问层,在数据访问层里写方法,在表示层在下拉列表控件产生一个事件,调用方法
更多追问追答
追问
这个我知道,就是问怎样实现上面的?
追答
数据访问层
public List GetAllStudents()
{
List students = new List();
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand comm = new SqlCommand("usp_SelectStudentsAll", conn);
comm.CommandType = CommandType.StoredProcedure;
conn.Open();
using (SqlDataReader dr = comm.ExecuteReader())
{
while (dr.Read())
{
Student student = new Student();
student.LoginId = Convert.ToString(dr["LoginId"]);
student.StudentNO = Convert.ToString(dr["StudentNO"]);
student.StudentName = Convert.ToString(dr["StudentName"]);
student.Sex = Convert.ToString(dr["Sex"]);
student.StudentIDNO = Convert.ToString(dr["StudentIDNO"]);
student.Phone = Convert.ToString(dr["Phone"]);
students.Add(student);
}
dr.Close();
}
conn.Close();
}
return students;
业务逻辑层
public List GetAllStudents()
{
return studentService.GetAllStudents();
}
表示层
private void ViewStudentForm_Load(object sender, EventArgs e)
{
dgvStudent.DataSource = studentManager.GetAllStudents();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询