◎现在数据库中建立test表,字段分别为I...... 现在数据库中建立test表,字段分别为ID、Code、Name; 数据库的链接这里就不具体写了,数据库的链接和操作请求我写在了AreaInfo.cs中,代码中会用到,这里声明一下 <%@ Page language="c#" Codebehind="Update.aspx.cs" AutoEventWireup="false" Inherits="Client.Page.AreaInfo.Update" %> Update.aspx.cs using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace Client.Page.AreaInfo { /// /// Update 的摘要说明。 /// public class Update : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DG1; protected Classes.AreaInfo myClass=new Client.Classes.AreaInfo(); private void Page_Load(object sender, System.EventArgs e) { if(!this.IsPostBack) { this.DG1.DataSource=myClass.bindGrid(); this.DG1.DataBind(); } // 在此处放置用户代码以初始化页面 } public void Page_Grid(Object sender, DataGridPageChangedEventArgs e) { DG1.CurrentPageIndex = e.NewPageIndex; DG1.DataSource =myClass.bindGrid(); DG1.DataBind(); } public void DG1_Edit(Object sender, DataGridCommandEventArgs e) { DG1.EditItemIndex = e.Item.ItemIndex; DG1.DataSource =myClass.bindGrid(); DG1.DataBind(); } public void DG1_Cancel(Object sender, DataGridCommandEventArgs e) { DG1.EditItemIndex = -1; DG1.DataSource = myClass.bindGrid(); DG1.DataBind(); } public void DG1_Update(Object sender, DataGridCommandEventArgs e) { string code = ((TextBox)e.Item.Cells[1].Controls[1]).Text; string name = ((TextBox)e.Item.Cells[2].Controls[1]).Text; int id=int.Parse(e.Item.Cells[0].Text); myClass.upDateArea(id,code,name); DG1.EditItemIndex = -1; DG1.DataSource = myClass.bindGrid(); DG1.DataBind(); } public void DG1_Delete(Object sender, DataGridCommandEventArgs e) { int id=int.Parse(e.Item.Cells[0].Text); myClass.deleteArea(id); this.DG1.DataSource=myClass.bindGrid(); this.DG1.DataBind(); } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } } |
|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )
GMT+8, 2024-10-1 01:22 , Processed in 0.135163 second(s), 12 queries , Gzip On, MemCache On.
Powered by Discuz! X3.5
© 2001-2023 Discuz! Team.