博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

费解gridview控件

Posted on 2009-04-08 22:23  terryida  阅读(185)  评论(2)    收藏  举报
下面的代码是gridview控件的使用.   
点击更新后,下面红色代码本来应该取得修改后的值,但是怎么还是取得的是原来的值呢?很费解.
是怎么回事呢?


protected void GridView1_RowUpdated(object sender, GridViewUpdateEventArgs e)
     {
        
       
         //Response.Write("<script>alert('"+e.RowIndex.ToString()+"');</script>");

         string sqlstr1 = "update userlogin set username='"
             + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim() + "',userpass='"
             + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "'"
          +" where userid=" + GridView1.DataKeys[e.RowIndex].Value.ToString();

        Label1.Text = sqlstr1;
         Label2.Text = "\n row index is " + e.RowIndex.ToString();

         OleDbCommand mycommand = new OleDbCommand(sqlstr1, conn);
         mycommand.CommandText = sqlstr1;
         mycommand.CommandType = CommandType.Text;

         conn.Open();

         mycommand.ExecuteNonQuery();
         conn.Close();

         GridView1.EditIndex = -1;
         bind();
         Label1.Visible = true;
       
       
     }