?? hmgl.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_hmgl : System.Web.UI.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();
OleDbCommand com = new OleDbCommand("select bsID,bsName from bmTable where bmID = '" + DropDownList1.Text.ToString().Trim() + "'", con);
OleDbDataReader ddrr = com.ExecuteReader();
this.DropDownList2.DataSource = ddrr;
this.DropDownList2.DataTextField = "bsName";
this.DropDownList2.DataValueField = "bsID";
this.DropDownList2.DataBind();
ddrr.Close();
con.Close();
BindToDataGrid();
}
}
private void BindToDataGrid()
{
OleDbConnection con =DB.mycon();
con.Open();
OleDbCommand cmd = new OleDbCommand("select bmTable.bmName,bmTable.bsName,telph.telnumber,telph.telperson from bmTable,telph where bmTable.bmID=telph.bmID and bmTable.bsID=telph.bsID and telph.bmID='"+DropDownList1.Text.Trim()+"' and telph.bsID='"+DropDownList2.Text.Trim()+"'",con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
this.DataGrid1.DataKeyField = "telnumber";
this.DataGrid1.DataSource = ds.Tables[0];
this.DataGrid1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand com = new OleDbCommand("select bsID,bsName from bmTable where bmID = '" + DropDownList1.Text.ToString().Trim() + "'", con);
OleDbDataReader ddrr = com.ExecuteReader();
this.DropDownList2.DataSource = ddrr;
this.DropDownList2.DataTextField = "bsName";
this.DropDownList2.DataValueField = "bsID";
this.DropDownList2.DataBind();
ddrr.Close();
BindToDataGrid();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
BindToDataGrid();
}
protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
{
string telnumber = this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand cmd = new OleDbCommand("delete from telph where bmID='"+DropDownList1.Text.Trim()+"' and bsID='"+DropDownList2.Text.Trim()+"' and telnumber='"+telnumber+"'",con);
cmd.ExecuteNonQuery();
con.Close();
BindToDataGrid();
}
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[4].Controls[0])).Attributes.Add("onclick", "return confirm('確認刪除嗎?');");
}
}
protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex = e.Item.ItemIndex;
BindToDataGrid();
}
protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{
string telnumber = this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
string telperson = ((TextBox)(e.Item.Cells[2].Controls[0])).Text;
string tel = ((TextBox)(e.Item.Cells[3].Controls[0])).Text;
//string bsName = ((TextBox)(e.Item.Cells[1].Controls[0])).Text;
OleDbConnection con = DB.mycon();
con.Open();
OleDbCommand cmd = new OleDbCommand("update telph set telperson='" + telperson + "',telnumber='" + tel + "' where telnumber='" + telnumber + "'", con);
cmd.ExecuteNonQuery();
BindToDataGrid();
}
protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex = -1;
BindToDataGrid();
}
protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindToDataGrid();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -