📄 updatestudent.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;
public partial class UpdateStudent : System.Web.UI.Page
{
int nStudentID = -1;
protected void Page_Load(object sender,EventArgs e)
{
///获取ID的值
if (Request.Params["StudentID"] != null)
{
nStudentID = Int32.Parse(Request.Params["StudentID"].ToString());
}
if (!Page.IsPostBack)
{
BindClassData();
if (nStudentID > -1)
{
///绑定控件的数据
BindStudentData(nStudentID);
}
}
///设置更新按钮的可用性
UpdateBtn.Enabled = ClassList.Items.Count <= 0 || nStudentID <= -1 ? false : true;
}
private void BindClassData()
{
///定义获取数据的类
Class gClass = new Class();
SqlDataReader rect = gClass.GetClasss();
///设定控件的数据源
ClassList.DataSource = rect;
///设定控件的Text属性和Value属性
ClassList.DataTextField = "Name";
ClassList.DataValueField = "ClassID";
///绑定控件的数据
ClassList.DataBind();
///关闭数据读取器和数据库的连接
rect.Close();
}
private void BindStudentData(int nStudentID)
{
///获取数据
Student student = new Student();
SqlDataReader recs = student.GetSingleStudent(nStudentID);
///读取数据
if (recs.Read())
{
///显示数据
Name.Text = recs["Name"].ToString();
Age.Text = recs["Age"].ToString();
Address.Text = recs["Address"].ToString();
Phone.Text = recs["Phone"].ToString();
Birthday.Text = recs["Birthday"].ToString();
EntranceDate.Text = recs["EntranceDate"].ToString();
Nationality.Text = recs["Nationality"].ToString();
Political.Text = recs["Political"].ToString();
NativePlace.Text = recs["NativePlace"].ToString();
IdentityCard.Text = recs["IdentityCard"].ToString();
Hukou.Text = recs["Hukou"].ToString();
Desn.Text = recs["Desn"].ToString();
ASPNET2System.SetListBoxItem(ClassList,recs["ClassID"].ToString());
ASPNET2System.SetListBoxItem(SexList,recs["Sex"].ToString());
ASPNET2System.SetListBoxItem(Maritallist,recs["Marital"].ToString());
ASPNET2System.SetListBoxItem(StateList,recs["State"].ToString());
}
recs.Close(); ///关闭数据源
}
protected void UpdateBtn_Click(object sender,EventArgs e)
{
///如果页面输入内容合法
if (Page.IsValid == true)
{
///定义类
StudentManager.Student student = new StudentManager.Student();
try
{
///修改
student.UpdateStudent(nStudentID,Int32.Parse(ClassList.SelectedValue),Name.Text,
Int32.Parse(Age.Text.Trim()),Int32.Parse(SexList.SelectedValue),
Address.Text.Trim(),Phone.Text.Trim(),
DateTime.Parse(Birthday.Text.Trim()),
DateTime.Parse(EntranceDate.Text.Trim()),
Nationality.Text.Trim(),Political.Text.Trim(),
NativePlace.Text.Trim(),IdentityCard.Text.Trim(),
Int32.Parse(Maritallist.SelectedValue),Hukou.Text.Trim(),
Int32.Parse(StateList.SelectedValue),Desn.Text);
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONUPDATESUCCESSMESSAGE + "')</script>");
}
catch (Exception ex)
{
///显示修改操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
}
protected void ReturnBtn_Click(object sender,EventArgs e)
{
///返回管理页面
Response.Redirect("~/DesktopModules/Student/StudentManage.aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -