protected void btnModificar_Click(object sender, EventArgs e) { List<Matricula> lstMatri = new List<Matricula>(); if (Session["Matri"] != null) { lstMatri = ((List<Matricula>)Session["Matri"]); } Matricula MatriculaEditada = lstMatri.SingleOrDefault(s => s.Codigo == Convert.ToInt32(txtCodigo.Text)); int indice = lstMatri.IndexOf(MatriculaEditada); MatriculaEditada.NombreEstud = txtNombre.Text; MatriculaEditada.Valor = Convert.ToInt32(txtValor.Text); lstMatri[indice] = MatriculaEditada; GridMatricula.DataSource = lstMatri; GridMatricula.DataKeyNames = new string[] { "Codigo" }; GridMatricula.DataBind(); }