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

📄 default.aspx.cs

📁 Linq三层模式之演示添加修改删除源码 net2008+sqlserver2005,利用Linq分三层操作数据
💻 CS
字号:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//Download from 51aspx.com/cv/LinqDemo
public partial class _Default : System.Web.UI.Page 
{

    StaffBLL sb = new StaffBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            bindData();
        }
    }

    private void bindData()
    {
        //StaffBLL sb = new StaffBLL();
        this.GridView1.DataSource = sb.LinqStaff();
        this.GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        this.GridView1.EditIndex = e.NewEditIndex;
        bindData();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value);
        TextBox staffTb = this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0] as TextBox;
        TextBox ageTb = this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox;
        string staffName = staffTb.Text;
        int  age = Convert.ToInt32(ageTb.Text);
        sb.LinqUpdateStaff(id, staffName, age);
        this.GridView1.EditIndex = -1;
        bindData();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        this.GridView1.EditIndex = -1;
        bindData();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        sb.LinqInsertStaff(this.TextBox1.Text,Convert.ToInt32(this.TextBox2.Text));
        bindData();
        this.TextBox1.Text = "";

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value);
        sb.LinqDeleteStaff(id);
        bindData();
    }
}

⌨️ 快捷键说明

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