?? dwgl.aspx.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 System.Data.OleDb;
public partial class Admin_dwgl : System.Web.UI.Page
{
//page加載事件
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BingtoDataGrid();
}
}
//綁定數(shù)據(jù)
private void BingtoDataGrid()
{
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand cmd = new OleDbCommand("select distinct bmID,bmName from bmTable", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
this.DataGrid1.DataKeyField = "bmID";
this.DataGrid1.DataSource = ds.Tables[0];
this.DataGrid1.DataBind();
}
//顯示特殊效果
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//鼠標(biāo)懸停高亮顯示
e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#fff5ee'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
//刪除詢問
((LinkButton)(e.Item.Cells[2].Controls[0])).Attributes.Add("onclick", "return confirm('確認(rèn)刪除嗎?');");
}
}
//編輯按鈕事件
protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex = e.Item.ItemIndex;
this.BingtoDataGrid();
}
//取消編輯事件
protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex = -1;
this.BingtoDataGrid();
}
//刪除按鈕事件
protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
{
string bmID = this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand cmd = new OleDbCommand("delete from bmTable where bmID='" + bmID.ToString().Trim() + "'", con);
OleDbCommand cmm = new OleDbCommand("delete from telph where bmID='" + bmID.ToString().Trim() + "'", con);
cmd.ExecuteNonQuery();
cmm.ExecuteNonQuery();
BingtoDataGrid();
con.Close();
}
//更新按鈕事件
protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{
string bmID = this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
string bmName = ((TextBox)(e.Item.Cells[1].Controls[0])).Text;
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand cmd = new OleDbCommand("update bmTable set bmName='" + bmName + "' where bmID='" + bmID + "'", con);
cmd.ExecuteNonQuery();
BingtoDataGrid();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -