📄 editexam.ascx.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 TeachHelper.BusinessLogicLayer;
using TeachHelper.Comm;
public partial class TeachHelper_Controls_EdirAchievement : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//对于没有数字的内容,下面这行完全满足要求,但加了数字就不行,必须调用OnItemDataBound
this.GridViewAchievement.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
if (!IsPostBack)
{
BindData();
}
}
protected void GridViewAchievement_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"" + e.Row.Style["BACKGROUND-COLOR"] + "\"");
//e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"" + "#add816" + "\"");
if (e.Row.Cells[11].Controls.Count > 0)
{
((ImageButton)(e.Row.Cells[11].Controls[0])).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}
}
protected void GridViewAchievement_RowEditing(object sender, GridViewEditEventArgs e)
{
((GridView)sender).EditIndex = e.NewEditIndex;
BindData();
DropDownListDepartment_SelectedIndexChanged(null, null);
}
protected void GridViewAchievement_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
ReturnBrowseMode();
}
protected void GridViewAchievement_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = this.GridViewAchievement.EditIndex;
GridViewRow row = this.GridViewAchievement.Rows[index];
int id = Convert.ToInt32(Server.HtmlDecode(row.Cells[0].Text.Trim()));
string name = ((TextBox)row.Cells[1].Controls[1]).Text.Trim();
string teacher = ((DropDownList)row.Cells[2].Controls[1]).SelectedValue;
int departmentId = Convert.ToInt32(((DropDownList)row.Cells[3].Controls[1]).SelectedValue);
int grade = Convert.ToInt32(((DropDownList)row.Cells[4].Controls[1]).SelectedValue);
int majorId = Convert.ToInt32(((DropDownList)row.Cells[5].Controls[1]).SelectedValue);
int classes = Convert.ToInt32(((DropDownList)row.Cells[6].Controls[1]).SelectedValue);
int subjectId = Convert.ToInt32(((DropDownList)row.Cells[7].Controls[1]).SelectedValue);
int examTypeId = Convert.ToInt32(((DropDownList)row.Cells[8].Controls[1]).SelectedValue);
DateTime time = new DateTime();
try
{
time = Convert.ToDateTime(((TextBox)row.Cells[9].Controls[1]).Text);
}
catch (Exception ex)
{
MessageBox.Show(this.Page, "输入的时间格式不正确");
}
Exam.Update(id, name, teacher, departmentId, grade, majorId, classes, subjectId, examTypeId, time);
ReturnBrowseMode();
}
protected void GridViewAchievement_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
}
protected void GridViewAchievement_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
}
protected void DropDownListDepartment_SelectedIndexChanged(object sender, EventArgs e)
{
int index = this.GridViewAchievement.EditIndex;
GridViewRow row = this.GridViewAchievement.Rows[index];
DropDownList ddlMajor = (DropDownList)row.Cells[5].FindControl("DropDownListMajor");
int departmentId = Convert.ToInt32(((DropDownList)row.Cells[3].Controls[1]).SelectedValue);
DataSet ds = Major.GetCollectByDepartmentId(departmentId);
ddlMajor.DataSource = ds;
ddlMajor.DataTextField = "Name";
ddlMajor.DataValueField = "Id";
ddlMajor.DataBind();
}
private void BindData()
{
this.GridViewAchievement.DataSource = Exam.GetCollect();
this.GridViewAchievement.DataBind();
}
private void ReturnBrowseMode()
{
this.GridViewAchievement.EditIndex = -1;
BindData();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -