日期:2014-05-18  浏览次数:20373 次

一道关于GridView中RowDeleting的问题
代码如下:    

protected   void   GridView2_RowUpdating(object   sender,   GridViewUpdateEventArgs   e)
        {
                   
                  string   sqlstrUD   =   "update   xsxx   set   ";
                sqlstrUD   += "xm=   ' "   +   ((TextBox)GridView2.Rows[e.RowIndex].Cells[2].Controls[0]).Text   +   " ', ";
                sqlstrUD   +=   "xb= ' "   +   ((TextBox)GridView2.Rows[e.RowIndex].Cells[3].Controls[0]).Text   +     " ', ";
                sqlstrUD   += "pwd= ' "   +   ((TextBox)GridView2.Rows[e.RowIndex].Cells[4].Controls[0]).Text   + " ', ";
                sqlstrUD   += "bjmc= ' "   +   ((TextBox)GridView2.Rows[e.RowIndex].Cells[5].Controls[0]).Text   + " ', ";
                sqlstrUD   += "zymc= ' "   +   ((TextBox)GridView2.Rows[e.RowIndex].Cells[6].Controls[0]).Text   + " ', ";  
                sqlstrUD   += "xxzydh= ' "   +   ((TextBox)GridView2.Rows[e.RowIndex].Cells[7].Controls[0]).Text   + " ' ";
                  sqlstrUD   +=   "   where   xh=   ' "   +   ((TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text   +   " ' ";
                 
              bool   test=     da.ExceSQL(sqlstrUD);         //调用方法执行SQL语句
              if(test==true)
              {
                Response.Write( "更新成功 ");
             
              }    
              else
              {
              Response.Write( "更新失败 ");
              }
              GridView2.EditIndex   =   -1;
              dlBind();
                   
  }
       
以上对数据库的更新完全可以,而下面的删除代码出了问题

        protected   void   GridView2_RowDeleting(object   sender,   GridViewDeleteEventArgs   e)
        {
          string   sqlstrDT= "delete   from   xsxx   where   xh= ";
            sqlstrDT   +=   "   ' "   +((TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text+ " ' ";