private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
this.datatomonmentsource();
}
// 在此处放置用户代码以初始化页面
}
private void datatomonmentsource()
{
OleDbConnection con=DBConn.createConn();
con.Open();
OleDbDataAdapter oda=new OleDbDataAdapter();
oda.SelectCommand=new OleDbCommand("select monmentID,productID,numofproduct,priceofproduct,usercount from monmentgood",con);
DataSet ds=new DataSet();
oda.Fill(ds,"monment");
this.DataGrid1.DataKeyField="monmentID";
this.DataGrid1.DataSource=ds.Tables["monment"].DefaultView;
this.DataGrid1.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex=e.Item.ItemIndex;
this.datatomonmentsource();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string userID=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
string usernum=((TextBox)e.Item.Cells[1].Controls[0]).Text;
OleDbConnection con=DBConn.createConn();
con.Open();
OleDbCommand cmd=new OleDbCommand("update monmentgood set numofproduct="+Convert.ToInt32(usernum)+" where monmentID="+Convert.ToInt32(userID),con);
cmd.ExecuteNonQuery();
this.DataGrid1.EditItemIndex=-1;
this.datatomonmentsource();
}
}
}