DataGrid编辑-删除-取消

{
 /// <summary>
 /// Update 的摘要说明。
 /// </summary>
 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();

  }

posted @ 2013-04-07 11:56  念余温  阅读(985)  评论(0编辑  收藏  举报