DataGridView的用法

2008-08-26 13:28:23.0     浏览:2703     来源:中国IT实验室
关键词:  DataGridView     用法  
...{

  string s = this.gvSupplier.DataKeys[e.NewEditIndex][1].ToString();

  this.txtAddr1.Text = "dddd " + s;

  this.gvSupplier.EditIndex = e.NewEditIndex;

  this.BindGvSupplier();

  }

  //点击取消按钮时触发的事件

  protected void gvSupplier_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)

  ...{

  this.gvSupplier.EditIndex = -1;

  this.BindGvSupplier();

  }

  //点击更新按钮时触发的事件

  protected void gvSupplier_RowUpdating(object sender, GridViewUpdateEventArgs e)

  ...{

  int id = e.RowIndex;

  GridViewRow gvr = this.gvSupplier.Rows[id];

  int suppId = int.Parse(((HyperLink)(gvr.Cells[7].Controls[0])).Text.ToString());

  string name = ((TextBox)gvr.Cells[0].Controls[0]).Text.ToString();

  string status = ((TextBox)gvr.Cells[1].Controls[0]).Text.ToString();

  string addr1 = ((TextBox)gvr.Cells[2].Controls[0]).Text.ToString();

  string addr2 =((TextBox) gvr.Cells[3].Controls[0]).Text.ToString();

  string city = ((TextBox)gvr.Cells[4].Controls[0]).Text.ToString();

  string state = ((TextBox)gvr.Cells[5].Controls[0]).Text.ToString();

  string zip=((TextBox)gvr.Cells[6].Controls[0]).Text.ToString();

  string sqlString = "update Supplier set Name= ' " + name + " ',Status= ' " + status + " ',Addr1= ' " + addr1 + " ',Addr2= ' " + addr2 + " ',City= ' " + city + " ',State= ' " + state + " ',Zip= ' " + zip + " ' where SuppId= " + suppId;

  int result = ExecuteSql(sqlString);

  if (result == 1)

  ...{

  //......

  }

  this.gvSupplier.EditIndex = -1;

  this.BindGvSupplier();

  }

  //增加一条记录

  protected void btnAdd_Click(object sender, EventArgs e)

  ...{

  string name = this.txtName.Text.ToString();

  string status = this.txtStatus.Text.ToString();

  string addr1 = this.txtAddr1.Text.ToString();

  string addr2 = this.txtAddr2.Text.ToString();

  string city = this.txtCity.Text.ToString();

  string state = this.txtState.Text.ToString();

  string zip = this.txtZip.Text.ToString();

  string sqlString = "insert into Supplier values(SQSuppId.Nextval, ' " + name + " ', ' " + status + " ', ' " + addr1 + " ', ' " + addr2 + " ', ' " + city + " ', ' " + state + " ', ' " + zip + " ') ";

  if (this.ExecuteSql(sqlString) == 1)

  ...{

  this.Alert( "你成功添加一条数据 ", this.Page);

  }

  else

  ...{

  this.Alert( "添加未成功! ", this.Page);

  }

  this.BindGvSupplier();

  }

[上一页]   [第1页]   [第2页]   [第3页]   [第4页]   [下一页]