温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:多功能在线考试系统改进版源码
当前文件:
OnLineExamUpdate/Web/MultiSelectManage.aspx.cs,打开代码结构图
OnLineExamUpdate/Web/MultiSelectManage.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 OnLineExam.BusinessLogicLayer; 12
13
public partial class Web_MultiSelectManage : System.Web.UI.Page 14
{ 15
protected void Page_Load(object sender, EventArgs e) 16
{ 17
if (!IsPostBack) 18
{ 19
string loginName = Session["userID"].ToString(); 20
Users user = new Users(); 21
user.LoadData(loginName); 22
labUser.Text = user.UserName; 23
InitDDLData(); //初始化考试科目 24
} 25
} 26
//初始化考试科目 27
protected void InitDDLData() 28
{ 29
Course course = new Course(); //创建考试科目对象 30
DataSet ds = course.QueryCourse(); //查询考试科目信息 31
ddlCourse.DataSource = ds; //指名考试科目列表框数据源 32
ddlCourse.DataTextField = "Name"; //DataTextField显示Name字段值 33
ddlCourse.DataValueField = "ID"; //DataValueField显示ID字段值 34
ddlCourse.DataBind(); //绑定数据 35
GridViewBind(); 36
} 37
//显示选择科目的单选题 38
protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e) 39
{ 40
GridViewBind();//为GridView绑定数据 41
} 42
protected void GridViewBind() 43
{ 44
MultiProblem multiproblem = new MultiProblem(); //创建多选题对象 45
DataSet ds = multiproblem.QueryMultiProblem(int.Parse(ddlCourse.SelectedValue));//根据考试科目查询多选题信息 46
GridView1.DataSource = ds.Tables[0].DefaultView; //为GridView控件指名数据源 47
GridView1.DataBind(); //绑定数据 48
} 49
//删除试题事件 50
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) 51
{ 52
MultiProblem multiproblem = new MultiProblem(); //创建单选题对象 53
int ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); //取出要删除记录的主键值 54
if (multiproblem.DeleteByProc(ID)) 55
{ 56
Response.Write("<script language=javascript>alert('成功删除试题!')</script>"); 57
} 58
else 59
{ 60
Response.Write("<script language=javascript>alert('删除试题失败!')</script>"); 61
} 62
GridViewBind();//重新绑定数据 63
} 64
//删除多条记录 65
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) 66
{ 67
MultiProblem multi = new MultiProblem();//创建MultiProblem对象 68
foreach (GridViewRow dr in GridView1.Rows)//对GridView中的每一行进行判断 69
{ 70
if (((CheckBox)dr.FindControl("xuanze")).Checked)//如果选择了进行删除 71
{ 72
int ID = int.Parse(((Label)dr.FindControl("Label1")).Text); 73
multi.ID = ID; 74
multi.DeleteByProc(ID); 75
} 76
} 77
} 78
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 79
{ 80
GridView1.PageIndex = e.NewPageIndex; 81
GridViewBind();//重新绑定数据 82
} 83
84
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 85
{ 86
if (e.Row.RowType == DataControlRowType.DataRow) 87
{ 88
e.Row.Cells[2].ToolTip = e.Row.Cells[2].Text; 89
if ((e.Row.Cells[2].Text).Length > 30) 90
{ 91
e.Row.Cells[2].Text = (e.Row.Cells[2].Text).Substring(0, 30) + "..."; 92
} 93
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) 94
{ 95
((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除\"" + e.Row.Cells[2].Text + "\"吗?')"); 96
} 97
98
} 99
int i; 100
//执行循环,保证每条数据都可以更新 101
for (i = 0; i < GridView1.Rows.Count; i++) 102
{ 103
//首先判断是否是数据行 104
if (e.Row.RowType == DataControlRowType.DataRow) 105
{ 106
//当鼠标停留时更改背景色 107
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='Aqua'"); 108
//当鼠标移开时还原背景色 109
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c"); 110
} 111
} 112
} 113
} 114






}