using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
namespace
考试系统.teacher
{
public
partial
class
StudentEdit : System.Web.UI.Page
{
kaoshidbEntities db =
new
kaoshidbEntities();
public
StudentInfo EditStudentInfo {
set
;
get
; }
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
ShowEditStundenInfo();
}
else
{
UpdateStudentInfo();
}
}
protected
void
ShowEditStundenInfo()
{
string
studentId = Request.QueryString[
"studentid"
].ToString();
StudentInfo studentInfo = db.StudentInfo.SingleOrDefault(S => S.StudentId == studentId);
if
(studentInfo !=
null
)
{
EditStudentInfo = studentInfo;
}
else
{
Response.Redirect(
"/MyErrorPage.aspx"
);
}
}
protected
void
UpdateStudentInfo()
{
string
studentId = Request.QueryString[
"studentid"
].ToString();
StudentInfo studentInfo = db.StudentInfo.SingleOrDefault(S => S.StudentId == studentId);
if
(studentInfo !=
null
)
{
studentInfo.StudentId = Request.Form[
"txtStudentId"
].ToString();
studentInfo.StudentName = Request.Form[
"txtStudentname"
].ToString();
}
int
r = db.SaveChanges();
if
(r > 0)
{
Response.Write(
"<script languge='javascript'>alert('添加成功!');window.location.href='StudentManage.aspx'</script>"
);
}
else
{
Response.Redirect(
"/MyErrorPage.aspx"
);
}
}
}
}