Hola soy yo de nuevo batallando con los gridviews de ASP.NET C# de casualidad el grid no hace nada cuando le inserto datos a la página, curiosamente si inserta en la base de datos y pues bueno necesito a fuerza que se visualicen esos datos.
Acá les adjunto mi código
STORE PROCEDURE
CREATE PROCEDURE
[dbo].[SP_LISTAR_DETALLE_FACTURA]
@pid_Factura int
AS
BEGIN
SELECT * FROM tb_detalle where id_Factura = @pid_Factura;
END
GO
CAPA_AD
public List<Detalle> Listar_Detalle(Detalle objetodetalle)
{
string connectionString = Conexion.cadenaConexion;
SqlConnection conn = new SqlConnection(connectionString);
List<Detalle> detallesencontrados = null;
SqlCommand cmd = new SqlCommand("SP_LISTAR_DETALLE_FACTURA", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pid_Factura", Convert.ToInt32(objetodetalle.Id_factura));
conn.Open();
// execute = cmd.ExecuteNonQuery();
SqlDataReader reader = cmd.ExecuteReader();
detallesencontrados = new List<Detalle>();
Detalle articulosaux = null;
while (reader.Read())
{
articulosaux = new Detalle();
articulosaux.Id_factura = Convert.ToInt32(reader[0]);
articulosaux.Codigo_articulo= Convert.ToInt32(reader[1]);
articulosaux.Descripcion= Convert.ToString(reader[2]);
articulosaux.Cantidad = Convert.ToInt32(reader[3]);
articulosaux.Monto = Convert.ToDouble(reader[4]);
articulosaux.Subtotal = Convert.ToDouble(reader[5]);
detallesencontrados.Add(articulosaux);
}
reader.Close();
conn.Close();
return detallesencontrados;
}
CAPA_LOGICA
public List<Detalle> Listar_Detalle(Detalle pdetalle)
{
List<Detalle> articuloslista = null;
Detalle_AD detallesAD = new Detalle_AD();
articuloslista = detallesAD.Listar_Detalle(pdetalle);
return articuloslista;
}
METODO EN EL FORMULARIO
private void llenar_grid(Detalle objeto)
{
List<Detalle> articulos_detalle = null;
DetalleLN logicaln = new DetalleLN();
articulos_detalle = logicaln.Listar_Detalle(objeto);
dgvDetalle.DataSource = articulos_detalle;
dgvDetalle.DataBind();
}
Y por último el método que llama desde el botón
double precio, cantidad, subtotal;
List<Detalle> detallelista = null;
if (txtcod.Text == "" || txtdescripcion.Text == "" || txtCantidad.Text == "" || txtcosto.Text == "" || txtNumeroFactura.Text == "")
{
Response.Write("Tienen que estar todos los espacios rellenados.");
}
else
{
Detalle Oobjeto = new Detalle();
Oobjeto.Codigo_articulo = Convert.ToInt32(txtcod.Text);
Oobjeto.Id_factura = Convert.ToInt32(txtNumeroFactura.Text);
Oobjeto.Descripcion = Convert.ToString(txtdescripcion.Text);
Oobjeto.Monto = Convert.ToDouble(txtcosto.Text);
Oobjeto.Cantidad = Convert.ToInt32(txtCantidad.Text);
cantidad = Convert.ToInt32(txtCantidad.Text);
precio = Convert.ToDouble(txtcosto.Text);
subtotal = precio * cantidad;
Oobjeto.Subtotal = subtotal;
DetalleLN objeto = new DetalleLN();
objeto.Agregar_Detalle(Oobjeto);
llenar_grid(Oobjeto);
sumarcolumna();
txtNumeroFactura.Enabled = false;
}
Pues ya he intentado de cualquier variedad de formas, no es posible que no pueda mostrar, que me falta!!?. Les agradezco mucho que se tomen la molestia de leerme, si saben por favor les agradecería una manita.
Saludos
Lo logré
Coloquen un sqlsource con parametro en el txtNumeroFactura.Text, luego realicen un dgvDetalle.Databind();
Listo , gracias.