📄 studentmanage.aspx.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 System.Data.SqlClient;
using StudentManager;
using SQLHelper;
public partial class StudentManage : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
if (!Page.IsPostBack)
{
///绑定控件的数据
BindStudentData();
}
///添加删除确认对话框
deleteBtn.Attributes.Add("onclick","return confirm('" + ASPNET2System.OPERATIONDELETEMESSAGE + "');");
}
private void BindStudentData()
{
///定义获取数据的类
Student student = new Student();
SqlDataReader recd = student.GetStudents();
///设定控件的数据源
StudentList.DataSource = recd;
///设定控件的Text属性和Value属性
StudentList.DataTextField = "Name";
StudentList.DataValueField = "StudentID";
///绑定控件的数据
StudentList.DataBind();
///关闭数据读取器和数据库的连接
recd.Close();
}
protected void AddBtn_Click(object sender,EventArgs e)
{
///跳转到添加页面
Response.Redirect("~/DesktopModules/Student/AddStudent.aspx");
}
protected void editBtn_Click(object sender,ImageClickEventArgs e)
{
if (StudentList.SelectedIndex > -1)
{
///跳转到查看页面
Response.Redirect("~/DesktopModules/Student/UpdateStudent.aspx?StudentID=" + StudentList.SelectedValue);
}
else
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
}
}
protected void deleteBtn_Click(object sender,ImageClickEventArgs e)
{
if (StudentList.SelectedIndex > -1)
{
///定义类Student
Student student = new Student();
try
{
///删除
student.DeleteStudent(Int32.Parse(StudentList.SelectedValue));
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONDELETESUCCESSMESSAGE + "')</script>");
///重新绑定数据
BindStudentData();
}
catch (Exception ex)
{
///显示添加操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
else
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -