Ver Mensaje Individual
  #11 (permalink)  
Antiguo 26/04/2016, 08:35
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

Este código traté de acomodar de acuerdo a lo que quieres hacer..podes copiar, pegar y luego los probas..
Código ASP:
Ver original
  1. <asp:GridView runat="server" ID="gvPrueba" AutoGenerateColumns="true"  >
  2. </asp:GridView>

Código ASP:
Ver original
  1. protected void Button2_Click(object sender, EventArgs e)
  2.     {
  3.         String codigo = tbCodigo.Text;
  4.         Conexion cnn = new Conexion();
  5.         cnn.conectar();
  6.        
  7.         DataTable aux = new DataTable();
  8.  
  9.         aux.Columns.Add("Producto");
  10.         aux.Columns.Add("Precio");
  11.         aux.Columns.Add("Codigo");
  12.         aux.Columns.Add("Cantidad");
  13.    
  14.         DataTable dt = new DataTable();
  15.         dt = cnn.consultarPro(codigo);
  16.        
  17.         try
  18.         {
  19.             if (dt.Rows.Count > 0)
  20.             {
  21.                 //este dato yo me lo inventé, vos debes saber en que posición
  22.                 //se encuentra el nombre del producto
  23.                 string producto = dt.Rows[0]["producto"].ToString();
  24.  
  25.                 int numero1 = Convert.ToInt32(dt.Rows[0]["precio"].ToString());
  26.                 int numero2 = Convert.ToInt32(TextBox3.Text);
  27.              
  28.                 int resultado = numero1 + numero2;
  29.                 TextBox2.Text = String.Empty;
  30.                 TextBox3.Text = resultado.ToString();
  31.                 int cantidad = int.Parse(Textotal.Text);
  32.                 cantidad++;
  33.                 Textotal.Text = cantidad.ToString();
  34.  
  35.                 Label11.Visible = true;
  36.                
  37.                 if (gvPrueba.Rows.Count == 0)
  38.                 {
  39.                     aux.Rows.Add(producto, num1, codigo, Textotal.Text);
  40.                     dtPrueba = aux;
  41.                 }
  42.                 else
  43.                 {
  44.                     aux = dtPrueba;
  45.                     aux.Rows.Add(producto, num1, codigo, Textotal.Text);
  46.                 }
  47.                 GridView2.DataSource = aux;
  48.                 GridView2.DataBind();
  49.             }
  50.             else
  51.             {
  52.                 Response.Write("no se encontro");
  53.                 TextBox2.Text = String.Empty;
  54.                
  55.             }
  56.         }
  57.         catch (SqlException ex)
  58.         {
  59.  
  60.             Response.Write("<center><h2>No se puede ejecutar</center></h2>" + ex.Message);
  61.         }
  62.         cnn.desconectar();
  63.     }
  64.  
  65.     private DataTable dtPrueba
  66.         {
  67.             get
  68.             {
  69.                 if (ViewState["dtPrueba"] != null)
  70.                     return (DataTable)ViewState["dtPrueba"];
  71.                 else
  72.                     return null;
  73.             }
  74.             set
  75.             {
  76.                 if (ViewState["dtPrueba"] != null)
  77.                     ViewState["dtPrueba"] = value;
  78.                 else
  79.                     ViewState.Add("dtPrueba", value);
  80.             }
  81.         }
Espero tus comentarios..