⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editsubject.ascx.cs

📁 学生成绩管理系统
💻 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_EditSubject : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //对于没有数字的内容,下面这行完全满足要求,但加了数字就不行,必须调用OnItemDataBound
        this.GridViewSubject.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");

        if (!IsPostBack)
        {
            BindData();
        }
    }

    protected void GridViewSubject_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 GridViewSubject_RowEditing(object sender, GridViewEditEventArgs e)
    {
        this.GridViewSubject.EditIndex = e.NewEditIndex;
        BindData();
    }

    protected void GridViewSubject_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        ReturnBrowseMode();
    }

    protected void GridViewSubject_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int index = Convert.ToInt32(e.RowIndex);
        GridViewRow row = this.GridViewSubject.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
            {
                Subject.Update(id, name);
                ReturnBrowseMode();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.Page, ex.Message);                
            }
        }        
    }

    protected void GridViewSubject_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
        
    }

    protected void GridViewSubject_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int index = Convert.ToInt32(e.RowIndex);
        GridViewRow row = this.GridViewSubject.Rows[index];
        int id = Convert.ToInt32(Server.HtmlDecode(row.Cells[0].Text.Trim()));

        try
        {
            Subject.Delete(id);
        }
        catch (Exception ex)
        {
            MessageBox.Show(this.Page, ex.Message);
        }
    }

    protected void GridViewSubject_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {

    }

    protected void GridViewSubject_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridViewSubject.PageIndex = e.NewPageIndex;
        BindData();
    }

    private void BindData()
    {
        this.GridViewSubject.DataSource = Subject.GetCollect();
        this.GridViewSubject.DataBind();
    }

    private void ReturnBrowseMode()
    {
        this.GridViewSubject.EditIndex = -1;
        BindData();
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -