为何在DataGrid中使用UpdateCommand无法实现数据的修改?(换种思维可以实现)

最近在在做一个.net的项目。令我不解的是,在使用datagrid的Update_Command事件时,第一次还可以实现在线编辑,等第二次再编辑的时候却没反应,而且也没有什么异常,加上断点想找原因呢,结果语句却执行。不知是什么原因?但是这并不意味着没有别的办法,我可以在datagrid加入一列超级链接列,通过单击链接,然后跳转到编辑页面。这样一样可以解决问题。
这是我在UpdateCommand中写的代码:
private void dgproducttype_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   int index=e.Item .ItemIndex ;
   string type=((TextBox)e.Item .Cells [1].Controls [0]).Text ;
   //取得编辑行的关键字
      int id=Convert.ToInt32 (this.dgproducttype .DataKeys[e.Item .ItemIndex ]);
   //int id=Convert.ToInt32 (this.dgproducttype .Items [index].Cells [0].Text );
   //改为下面的写法后,则提示:输入字符串的格式不正确
   string sql="update ProductType set type='"+type+"' where typeId='"+id+"'";
   try
   {
    Db.ExecuteIUDSql (sql);
    this.dgproducttype .EditItemIndex =-1;
    this.DataGridBind ();
   }
   catch(OleDbException ex)
   {
    this.Response .Write (ex.Message .ToString ());
   }

posted @ 2008-06-15 14:52  tan_goahead  阅读(336)  评论(0)    收藏  举报