Ver Mensaje Individual
  #8 (permalink)  
Antiguo 21/04/2016, 12:57
uagrm
 
Fecha de Ingreso: agosto-2010
Mensajes: 126
Antigüedad: 13 años, 8 meses
Puntos: 9
Respuesta: Listar nombres cada que se presiona boton

Tu error es por que no le estás pasando los parámetro al t.Rows.Add(). Bueno, hice una modificación rápida el código, pero sí funciona.
Código ASP:
Ver original
  1. protected void OnClick_btnAgregar(object sender, EventArgs e)
  2.         {
  3.             adicionarFila();
  4.         }
  5.        
  6.         private void adicionarFila()
  7.         {
  8.             //Id, Nombre, Apellido
  9.             Alumno a = new Alumno();
  10.            
  11.             DataTable dt = new DataTable();
  12.             dt = a.Alumno_Obtener_PorCodigo(Int32.Parse(tbCodigo.Text));
  13.  
  14.             if (dt != null)
  15.             {
  16.                 if (dt.Rows.Count > 0)
  17.                 {
  18.                     string id = dt.Rows[0]["Codigo"].ToString();
  19.                     string codigo = dt.Rows[0]["Nombre"].ToString();
  20.                     string descripcion = dt.Rows[0]["Apellido"].ToString();
  21.  
  22.                     if (gvPrueba.Rows.Count == 0)
  23.                     {
  24.                         dtPrueba = dt;
  25.                     }
  26.                     else
  27.                     {
  28.                         dt = dtPrueba;
  29.                         dt.Rows.Add(id, codigo, descripcion);
  30.                     }
  31.                     gvPrueba.DataSource = dt;
  32.                     gvPrueba.DataBind();
  33.                 }
  34.             }
  35.         }
  36.  
  37.         private DataTable dtPrueba
  38.         {
  39.             get
  40.             {
  41.                 if (ViewState["dtPrueba"] != null)
  42.                     return (DataTable)ViewState["dtPrueba"];
  43.                 else
  44.                     return null;
  45.             }
  46.             set
  47.             {
  48.                 if (ViewState["dtPrueba"] != null)
  49.                     ViewState["dtPrueba"] = value;
  50.                 else
  51.                     ViewState.Add("dtPrueba", value);
  52.             }
  53.         }
Saludos,