断点看下GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString()什么内容

解决方案 »

  1.   

     String strConnection = ConfigurationSettings.AppSettings["connstring"];
            SqlConnection myConnection = new SqlConnection(strConnection);        SqlCommand cm = new SqlCommand("updateu", myConnection);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Connection.Open();
            Guid userID;
            string userLogName,username, sex, phone, mobilephone;        userID = new Guid(GridView1.Rows[e.RowIndex].
            Cells[0].Controls[0].ToString());
            userLogName = ((TextBox)GridView1.Rows[e.RowIndex].
            Cells[1].Controls[0]).Text;
            username = ((TextBox)GridView1.Rows[e.RowIndex].
            Cells[3].Controls[0]).Text;
            sex = ((TextBox)GridView1.Rows[e.RowIndex].
           Cells[4].Controls[0]).Text;
            phone = ((TextBox)GridView1.Rows[e.RowIndex].
            Cells[5].Controls[0]).Text;
            mobilephone = ((TextBox)GridView1.Rows[e.RowIndex].
            Cells[5].Controls[0]).Text;        cm.Parameters.Add(new SqlParameter("@userid", userID));
            cm.Parameters.Add(new SqlParameter("@userLogName", userLogName));
            cm.Parameters.Add(new SqlParameter("@username ", username));
            cm.Parameters.Add(new SqlParameter("@sex",sex));
            cm.Parameters.Add(new SqlParameter("@phone", phone));
            cm.Parameters.Add(new SqlParameter("@mobilephone", mobilephone));
            cm.ExecuteNonQuery();        GridView1.EditIndex = -1;
            Bindgridview();
      

  2.   

    还没搞定啊?
    目前的情况明显是GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString()格式不对吗,你看看这里到底显示的是什么
      

  3.   

    是啊,userID = {00000000-0000-0000-0000-000000000000}
      

  4.   

    把userID该成字符串类型,看看
      

  5.   

    肯定是修改啊,但是我更新的那条USERID不是空啊,怪事!!
      

  6.   

    添加UserID
    string userID= System.Guid.NewGuid().ToString().Trim();            
      

  7.   

    那你绑定显示到gridview时就有问题啊,跟踪一下吧
      

  8.   

    strConnection 这个地方就是null晕啊,不知咋回事
      

  9.   

      绑定显示到gridview时应该没问题啊:如下:  private void Bindgridview()
        {
            String strConnection = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];        //String strConnection = ConfigurationSettings.AppSettings["connstring"];        SqlConnection myConnection = new SqlConnection(strConnection);
            //SqlDataAdapter da = new SqlDataAdapter("select * from users order by sysdate desc", myConnection);        SqlDataAdapter da = new SqlDataAdapter("select * from users", myConnection);
            DataSet ds = new DataSet();
            da.Fill(ds, "users");
            DataView dv = ds.Tables[0].DefaultView;
            if (ViewState["sortexpression"] != null)
            {
                dv.Sort = ViewState["sortexpression"].ToString() + " " + ViewState["sortdirection"].ToString();
            }        GridView1.DataSource = dv;
            GridView1.DataBind();
        }