以下是引用片段:
其实现代码如下: protected void Page_Load(object sender, EventArgs e) { // 在此处放置用户代码以初始化页面 if (!Page.IsPostBack) { this.GridView1.DataSource = Database.Get_Table("select * from 班级 "); this.GridView1.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { //跳转页面 Response."); } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { string Key = this.GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)]["班级代码"].ToString(); if (e.CommandName == "Mod") { //传递修改的标志 跳转页面 Response.?ID=" + Key); } else if (e.CommandName == "Del") { if (Database.Get_Table("select * from 学生 where 班级代码=" + Key + "").Rows.Count > 0) { Page.>alert('班级信息使用中');"); return; } //删除信息 Database.ExecSql("delete from 班级 where 班级代码=" + Key + ""); this.GridView1.DataSource = Database.Get_Table("select * from 班级 "); this.GridView1.DataBind(); } } } protected void Page_Load(object sender, EventArgs e) { // 在此处放置用户代码以初始化页面 if (!Page.IsPostBack) { if (Request.QueryString["ID"] != null) { //显示当前的班级信息 DataTable tmpda = new DataTable(); tmpda = Database.Get_Table("select * from 班级 where 班级代码=" + Request.QueryString["ID"]); if (tmpda.Rows.Count > 0) { this.TextBox1.Text = tmpda.Rows[0]["班级名称"].ToString(); this.TextBox3.Text = tmpda.Rows[0]["班主任姓名"].ToString(); this.TextBox2.Text = tmpda.Rows[0]["班主任帐号"].ToString(); } } }
} protected void Button1_Click(object sender, EventArgs e) { //根据标志判断是添加还是修改的操作 保存班级信息 if (Request.QueryString["ID"] != null) { if (Database.Get_Table("select * from 班级 where 班主任帐号='" + TextBox2.Text + "' and 班级代码<>" + Request.QueryString["ID"] + "").Rows.Count > 0) { Page.>alert('班主任帐号重复');"); return;
} Database.ExecSql("update 班级 set 班级名称='" + TextBox1.Text + "',班主任姓名='" + TextBox3.Text + "', 班主任帐号='" + TextBox2.Text + "' where 班级代码=" + Request.QueryString["ID"]); } else { if (Database.Get_Table("select * from 班级 where 班主任帐号='" + TextBox2.Text + "'").Rows.Count > 0) { Page.>alert('班主任帐号重复'>"); return;
} Database.ExecSql("insert into 班级(班级名称,班主任帐号,班主任密码,班主任姓名) values('" + TextBox1.Text + "'" + " ,'" + TextBox2.Text + "','000000','" + TextBox3.Text + "')");
} }
|