日期:2014-05-17  浏览次数:20595 次

GridView的更新事件 在线等 贴了一天了没有人理 求指教啊
//更新事件
protected void xgvRealtionList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
  GridViewRow row = (GridViewRow)xgvRealtionList.Rows[e.RowIndex];
  TextBox txteeName = row.FindControl("txteeName") as TextBox;
  TextBox txterName = row.FindControl("txterName") as TextBox;
  TextBox txtdeName = row.FindControl("txtdeName") as TextBox;
  TextBox txtewName = row.FindControl("txtewName") as TextBox;
  //获取到要更新的内容后如何进行更新,我的数据源是DataTable, DataTable中的数据是从Execl表格中获取
  //也就是说我的数据更新要在DataTable中执行,请帮小弟写出源码
   
}

------解决方案--------------------
DataRow[] arrDr = dt.Select("条件"); -- 最好是主键,查出DataTable中唯一一条数据
DataRow dr = arrDr[0];
dr.BeginEdit();
GridViewRow row = (GridViewRow)xgvRealtionList.Rows[e.RowIndex];
TextBox txteeName = row.FindControl("txteeName") as TextBox;
TextBox txterName = row.FindControl("txterName") as TextBox;
TextBox txtdeName = row.FindControl("txtdeName") as TextBox;
TextBox txtewName = row.FindControl("txtewName") as TextBox;
dr["字段名"] = txteeName.Text;
....给dr要修改的字段赋值
dr.EndEdit();
dt.AcceptChange();