📄 editmajor.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_EditMajor : System.Web.UI.UserControl
{
int departmentId;
int majorId;
string majorName;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.DropDownListDepartment.DataBind();
BindData();
}
}
protected void DropDownListDepartment_SelectedIndexChanged(object sender, EventArgs e)
{
BindData();
}
protected void GridViewMajor_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[3].Controls.Count > 0)
{
((ImageButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}
}
protected void GridViewMajor_RowEditing(object sender, GridViewEditEventArgs e)
{
((GridView)sender).EditIndex = e.NewEditIndex;
BindData();
}
protected void GridViewMajor_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
GridViewRow row = ((GridView)sender).Rows[index];
int id = Convert.ToInt32(Server.HtmlDecode(row.Cells[0].Text.Trim()));
string name = ((TextBox)row.Cells[1].Controls[0]).Text.Trim();
if (string.IsNullOrEmpty(name))
{
MessageBox.Show(this.Page, "名字不能为空");
}
else
{
try
{
Major.Update(id, name);
ReturnBrowseMode();
}
catch (Exception ex)
{
MessageBox.Show(this.Page, ex.Message);
}
}
}
protected void GridViewMajor_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
GridViewRow row = ((GridView)sender).Rows[index];
int id = Convert.ToInt32(Server.HtmlDecode(row.Cells[0].Text.Trim()));
try
{
Major.Delete(id);
}
catch (Exception ex)
{
MessageBox.Show(this.Page, ex.Message);
}
}
protected void GridViewMajor_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
ReturnBrowseMode();
}
protected void GridViewMajor_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
((GridView)sender).PageIndex = e.NewPageIndex;
BindData();
}
private void BindData()
{
departmentId = Convert.ToInt32(this.DropDownListDepartment.SelectedValue.Trim());
this.GridViewMajor.DataSource = Major.GetCollectByDepartmentId(departmentId);
this.GridViewMajor.DataBind();
}
private void ReturnBrowseMode()
{
this.GridViewMajor.EditIndex = -1;
BindData();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -