admin_gg.aspx.cs

来自「企业网站管理系统(C#.NET2003开发),供初学者学习!」· CS 代码 · 共 67 行

CS
67
字号
using System;
using System.Data;
using System.Data.OleDb;
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;

public partial class Admin_Admin_Gg : System.Web.UI.Page
{
    OleDbConnection MyConn;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserID"] == "" || Session["UserID"] == null)
        {
            Response.Write("<script language=javascript>window.alert('为了系统安全,请您重新登陆');window.location.href=('Admin_Login.aspx')</script>");
        }
        this.DataToBind();
    }
    private void DataToBind()
    {
        string ptype = Request.QueryString["p"];
        MyConn = DB.CreateDB();
        MyConn.Open();
        OleDbCommand cmd = new OleDbCommand("select * from product where pro_name='"+ptype+"'", MyConn);
        DataSet ds = new DataSet();
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        da.Fill(ds, "product");
        this.GgGrid.DataKeyField = "id";
        this.GgGrid.DataSource = ds;
        this.GgGrid.DataBind();
        MyConn.Close();
    }
    protected void GgGrid_DeleteCommand(object source, DataGridCommandEventArgs e)
    {

        MyConn = DB.CreateDB();
        MyConn.Open();
        string ID = this.GgGrid.DataKeys[e.Item.ItemIndex].ToString();
        OleDbCommand cmd1 = new OleDbCommand("delete from product where id=" + ID, MyConn);
        cmd1.ExecuteNonQuery();
        MyConn.Close();
        this.DataToBind();

    }
    protected void GgGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#1e90ff'");
            e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            ((LinkButton)(e.Item.Cells[2].Controls[0])).Attributes.Add("onclick", "return confirm('确认删除?')");

        }
    }
    protected void GgGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        this.GgGrid.CurrentPageIndex = e.NewPageIndex;
        this.DataToBind();
    }

}

⌨️ 快捷键说明

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