📄 editdepartment.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.Comm;
using TeachHelper.BusinessLogicLayer;
public partial class TeachHelper_Controls_EditDepartment : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
protected void GridViewDepartment_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 GridViewDepartment_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridViewDepartment.EditIndex = e.NewEditIndex;
BindData();
}
protected void GridViewDepartment_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
ReturnBrowseMode();
}
protected void GridViewDepartment_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
GridViewRow row = this.GridViewDepartment.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
{
Department.Update(id, name);
ReturnBrowseMode();
}
catch (Exception ex)
{
MessageBox.Show(this.Page, ex.Message);
}
}
}
protected void GridViewDepartment_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
}
protected void GridViewDepartment_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
GridViewRow row = this.GridViewDepartment.Rows[index];
int id = Convert.ToInt32(Server.HtmlDecode(row.Cells[0].Text.Trim()));
try
{
Department.Delete(id);
}
catch (Exception ex)
{
MessageBox.Show(this.Page, ex.Message);
}
BindData();
}
protected void GridViewDepartment_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridViewDepartment.PageIndex = e.NewPageIndex;
BindData();
}
private void BindData()
{
this.GridViewDepartment.DataSource = Department.GetCollect();
this.GridViewDepartment.DataBind();
}
private void ReturnBrowseMode()
{
this.GridViewDepartment.EditIndex = -1;
BindData();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -