?? admin_guest.aspx.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('為了系統(tǒng)安全,請您重新登陸');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('確認(rèn)刪除?')");
}
}
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();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -