Beispiel #1
0
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //TextBox txtId = (TextBox)GridView1.Rows[e.RowIndex].FindControl("lblID");
            //TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("lblname");
            //TextBox txtPassword = (TextBox)GridView1.Rows[e.RowIndex].FindControl("lblPassword");
            //TextBox txtEmail = (TextBox)GridView1.Rows[e.RowIndex].FindControl("lblEmail");
            //TextBox txtAddress = (TextBox)GridView1.Rows[e.RowIndex].FindControl("lblAddress");
            //TextBox txtMobile = (TextBox)GridView1.Rows[e.RowIndex].FindControl("lblMobile");
            //TextBox txtDob = (TextBox)GridView1.Rows[e.RowIndex].FindControl("lbldob");
            //con.Open();

            //SqlCommand cmd = new SqlCommand("UPDATE user SET id ='" + txtId.Text + "',name ='" + txtName.Text + "',password ='******',email ='" + txtEmail.Text + "',address ='" + txtAddress.Text + "',mobile ='" + txtMobile.Text + "',dob ='" + txtDob.Text + "'  WHERE id='" + txtId.Text + "'");


            int         userid      = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
            GridViewRow row         = (GridViewRow)GridView1.Rows[e.RowIndex];
            Label       lblID       = (Label)row.FindControl("lblID");
            TextBox     txtName     = (TextBox)row.Cells[0].FindControl("lblname");
            TextBox     txtEmail    = (TextBox)row.Cells[1].FindControl("lblPassword");
            TextBox     txtPassword = (TextBox)row.Cells[2].FindControl("lblEmail");
            TextBox     txtAddress  = (TextBox)row.Cells[3].FindControl("lblAddress");
            TextBox     txtMobile   = (TextBox)row.Cells[4].FindControl("lblMobile");
            TextBox     txtDob      = (TextBox)row.Cells[5].FindControl("lblEmail");


            GridView1.EditIndex = -1;
            con.Open();
            //SqlCommand cmd = new SqlCommand("SELECT * FROM detail", conn);
            //SqlCommand cmd = new SqlCommand("update detail set name='" + textName.Text + "',address='" + textadd.Text + "',country='" + textc.Text + "'where id='" + userid + "'", conn);
            SqlCommand cmd = new SqlCommand("UPDATE user SET id ='" + lblID.Text + "',name ='" + txtName.Text + "',password ='******',email ='" + txtEmail.Text + "',address ='" + txtAddress.Text + "',mobile ='" + txtMobile.Text + "',dob ='" + txtDob.Text + "'  WHERE id='" + userid + "'");


            cmd.ExecuteNonQuery();
            GvBindProfile();
            con.Close();
        }