?? bmgl.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_bmgl : System.Web.UI.Page
{
//page加載事件
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand cmm = new OleDbCommand("select distinct bmID,bmName from bmTable", con);
OleDbDataReader ddr = cmm.ExecuteReader();
this.DropDownList1.DataSource = ddr;
this.DropDownList1.DataTextField = "bmName";
this.DropDownList1.DataValueField = "bmID";
this.DropDownList1.DataBind();
ddr.Close();
con.Close();
BindToDataGrid(DropDownList1.Text.Trim());
}
}
//數據填充方法
private void BindToDataGrid(string ss)
{
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand cmd = new OleDbCommand("select bmID,bsID,bsName from bmTable where bmID='"+ss+"'", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"bmTable");
this.DataGrid1.DataKeyField = "bsID";
this.DataGrid1.DataSource = ds.Tables["bmTable"];
this.DataGrid1.DataBind();
}
private void BindTo()
{
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand cmd = new OleDbCommand("select bmID,bsID,bsName from bmTable", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "bmTable");
this.DataGrid1.DataKeyField = "bsID";
this.DataGrid1.DataSource = ds.Tables["bmTable"];
this.DataGrid1.DataBind();
}
//分頁
protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
this.BindToDataGrid(DropDownList1.Text.Trim());
}
//高亮顯示
protected void DataGrid1_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='#fff5ee'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
//刪除詢問
((LinkButton)(e.Item.Cells[2].Controls[0])).Attributes.Add("onclick", "return confirm('確認刪除嗎?');");
}
}
//編輯按鈕事件
protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex = e.Item.ItemIndex;
this.BindToDataGrid(DropDownList1.Text.Trim());
}
//更新按鈕事件
protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{
string bsID = this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
string bsName = ((TextBox)(e.Item.Cells[1].Controls[0])).Text;
//string bmName = ((TextBox)(e.Item.Cells[2].Controls[0])).Text;
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand cmd = new OleDbCommand("update bmTable set bsName='" + bsName + "' where bsID='" + bsID + "' and bmID='"+DropDownList1.Text.Trim()+"'", con);
cmd.ExecuteNonQuery();
this.BindToDataGrid(DropDownList1.Text.Trim());
}
//取消按鈕事件
protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex = -1;
this.BindToDataGrid(DropDownList1.Text.Trim());
}
//刪除按鈕事件
protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
{
string bsID = this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand cmd = new OleDbCommand("delete from bmTable where bmID='" + DropDownList1.Text.Trim() + "' and bsID='" +bsID+ "'", con);
OleDbCommand cmm = new OleDbCommand("delete from telph where bmID='" + DropDownList1.Text.Trim() + "' and bsID='" + bsID + "'", con);
cmd.ExecuteNonQuery();
cmm.ExecuteNonQuery();
this.BindToDataGrid(DropDownList1.Text.Trim());
}
//下拉列表事件
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string sd = DropDownList1.Text.Trim();
this.BindToDataGrid(sd);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -