How can I create a list

Asked

Viewed 76 times

-1

I need to create a list, where it will list all existing items within an order.

In the method below I can bring an item, but I can’t bring it if I have more than one. My doubt would be, I have to create a method in the code behind and in the classe I don’t know how list logic works.

Code (please observe line [itemPedido]):

protected void ExibirProtocoloPedido(PedidoVenda objPed)
{
    try
    {
       PedidoVendaItens objItPed = new PedidoVendaItens();
       Produtos objProd = new Produtos();

    Session["pedEmpresa"] = objPed.PedEmpresa;
    Session["numPedido"] = objPed.PedNumero;
    Session["msgOfertas"] = (!string.IsNullOrEmpty(objPed.pedMsgOfertas.ToString()) ? objPed.pedMsgOfertas.ToString() : "");            
    Session["itemPedido"] = objItPed.ItPProduto + " - " + objProd.ProdDescr + "/" + "Qtde.:" + objItPed.ItPQtde  + " / " + "Total:" + objItPed.ItPrecoComp;
    Session["msgMatApoio"] = (!string.IsNullOrEmpty(objPed.pedMsgMatApoio.ToString()) ? objPed.pedMsgMatApoio.ToString() : "");
    Session["msgReorderGerado"] = (!string.IsNullOrEmpty(objPed.pedMsgReorderGerado.ToString()) ? objPed.pedMsgReorderGerado.ToString() : "");
    Session["msgReorderAtendido"] = (!string.IsNullOrEmpty(objPed.pedMsgReorderAtendido.ToString()) ? objPed.pedMsgReorderAtendido.ToString() : "");
    Session["msgReorderNaoAtendido"] = (!string.IsNullOrEmpty(objPed.pedMsgReorderNaoAtendido.ToString()) ? objPed.pedMsgReorderNaoAtendido.ToString() : "");
    Session["msgPendencias"] = (!string.IsNullOrEmpty(objPed.pedMsgPendencias.ToString()) ? objPed.pedMsgPendencias.ToString() : "");
    Session["valorPedido"] = (!string.IsNullOrEmpty(txtValACobrar.Text) ? string.Format("{0:0,0.00}", txtValACobrar.Text) : "0");
    Session["statusPed"] = objPed.PedStatus;
    Session["formaPagto"] = objPed.PedForPgto;
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "ShowProtocolo();", true);
}
catch (Exception ex)
{
    throw ex;
    }
}

The result that returns me from this method is:

2210 - Devione 125ML / Qty.: 1 / Total: 15.75

  • The first thing you should do in this code is take the try-catch, is doing nothing. It is actually doing something, harming the stack trace, but nothing useful. I don’t understand what you want to know. Which lists? There are many. What logic? What do you want to do?

  • @bigown Would list item by item, separating by line... As I mentioned in the question, this method lists an item. Now when you have more than one item, it only brings the first item, so I wanted to know how to create a & #Xa; list type to create number of lines according to the amount of items in the order.

2 answers

1


You need to create an object of type List Pedidovendaitems

Thus:

List<PedidoVendaItens> objLista = new List<PedidoVendaItens>();

Then use the Add method to add items to the list.

-1

Dude, what I get from the question is that you need to put a list of products inside the session. Is that it? If it is, you cannot place the list as an object. You will need to serialize your list. If this is the case, I recommend newtonsoft.

If that is not the question, can you enlighten me a little more?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.