温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:大学生调查投票系统源码
当前文件:
StudentVote/Edit.aspx.cs,打开代码结构图
StudentVote/Edit.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
13
public partial class Edit : System.Web.UI.Page 14
{ 15
protected void Page_Load(object sender, EventArgs e) 16
{ 17
string StrID = Request["ID"]; 18
string Com = "select * from tb_Vote where ID='"+StrID+"'"; 19
SqlConnection Sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConStr"]); 20
Sqlcon.Open(); 21
SqlCommand SqlCom = new SqlCommand(Com, Sqlcon); 22
SqlDataReader dr = SqlCom.ExecuteReader(); 23
dr.Read(); 24
if (!IsPostBack) 25
{ 26
this.txtSubject.Text = dr["Title"].ToString(); 27
this.txtContent.Text = dr["Content"].ToString().Replace("|", "\n"); 28
} 29
dr.Close(); 30
} 31
32
protected void btnUpdate_Click(object sender, EventArgs e) 33
{ 34
string StrContent = this.txtContent.Text.Trim().Replace("\n", "|"); 35
string[] StrEvery = StrContent.Split('|'); 36
foreach (string str in StrEvery) 37
{ 38
if (str.Split(',').Length > 0) 39
{ 40
if (str.IndexOf(',') <= 0) 41
{ 42
Response.Write("<script language=javascript>alert('格式错误!');location='javascript:history.go(-1)'</script>"); 43
return; 44
} 45
} 46
} 47
string Com = "Update tb_Vote Set Title='" + this.txtSubject.Text + "',Content='" + StrContent + "' where ID=" + Request["ID"] + ""; 48
SqlData da = new SqlData(); 49
bool update = da.ExceSQL(Com); 50
if (update == true) 51
{ 52
Response.Write("<script language=javascript>alert('修改成功!');location='Index.aspx'</script>"); 53
} 54
else 55
{ 56
Response.Write("<script language=javascript>alert('修改失败!');location='javascript:history.go(-1)'</script>"); 57
} 58
} 59
protected void btnDelete_Click(object sender, EventArgs e) 60
{ 61
string Com = "delete from tb_Vote where ID="+Request["ID"]+""; 62
SqlData da = new SqlData(); 63
bool delete = da.ExceSQL(Com); 64
if (delete) 65
{ 66
Response.Write("<script language=javascript>alert('删除成功!');location='Index.aspx'</script>"); 67
} 68
else 69
{ 70
Response.Write("<script language=javascript>alert('删除失败!');location='javascript:history.go(-1)'</script>"); 71
} 72
} 73
} 74





}
}