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

📄 admin_guest.aspx.cs

📁 企业网站管理系统(C#.NET2003开发),供初学者学习!
💻 CS
字号:
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_Guest : 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>");
        }
        if (!IsPostBack)
        {
            this.DataToBind();
        }
    }
    public void DataToBind()
    {
        MyConn = DB.CreateDB();
        MyConn.Open();
        OleDbCommand cmd = new OleDbCommand("select * from guestbook order by id desc", MyConn);
        DataSet ds = new DataSet();
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        da.Fill(ds, "guestbook");
        this.GuestList.DataSource = ds;
        this.GuestList.DataKeyField = "id";
        this.GuestList.DataBind();
        MyConn.Close();
    }

    protected void GuestList_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");
            //((Button)(e.Item.Cells[0].Controls[0])).Attributes.Add("onclick", "return confirm('确认删除?')");

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

  
    protected void BtnDelete_Command(object sender, CommandEventArgs e)
    {
        
        MyConn = DB.CreateDB();
        int id = int.Parse(e.CommandArgument.ToString());
        Response.Write(id);
        //this.GuestList.DataKeys[e.Item.ItemIndex].ToString();
        //MyConn.Open();
        //OleDbCommand cmd = new OleDbCommand("delete from guestbook where id=" + id, MyConn);
        //cmd.ExecuteNonQuery();
        //MyConn.Close();
        //this.DataToBind();
    }

 
}

⌨️ 快捷键说明

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