📄 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.Linq;
using System.Collections.Generic;
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()
{
///定义获取数据的类
ClassM gClass = new ClassM();
Table<Class> rect = gClass.GetClasss();
///设定控件的数据源
ClassList.DataSource = rect;
///设定控件的Text属性和Value属性
ClassList.DataTextField = "Name";
ClassList.DataValueField = "ClassID";
///绑定控件的数据
ClassList.DataBind();
}
private void BindStudentData(int nStudentID)
{
///获取数据
StudentM student = new StudentM();
Student recs = student.GetSingleStudent(nStudentID);
///读取数据
if (recs !=null)
{
///显示数据
Name.Text = recs.Name;
Age.Text = recs.Age.ToString();
Address.Text = recs.Address;
Phone.Text = recs.Phone;
Birthday.Text = recs.Birthday.ToString();
EntranceDate.Text = recs.EntranceDate.ToString();
Nationality.Text = recs.Nationality;
Political.Text = recs.Political;
NativePlace.Text = recs.NativePlace;
IdentityCard.Text = recs.IdentityCard;
Hukou.Text = recs.Hukou;
Desn.Text = recs.Desn;
ASPNET35System.SetListBoxItem(ClassList,recs.ClassID.ToString());
ASPNET35System.SetListBoxItem(SexList,recs.Sex.ToString());
ASPNET35System.SetListBoxItem(Maritallist,recs.Marital.ToString());
ASPNET35System.SetListBoxItem(StateList,recs.State.ToString());
}
}
protected void UpdateBtn_Click(object sender,EventArgs e)
{
///如果页面输入内容合法
if (Page.IsValid == true)
{
///定义类
StudentM student = new StudentM();
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('" + ASPNET35System.OPERATIONUPDATESUCCESSMESSAGE + "')</script>");
}
catch (Exception ex)
{
///显示修改操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET35System.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 + -