Solved

how to display mulitple itemNo's in literal or repeater or any other control

Posted on 2008-10-20
8
176 Views
Last Modified: 2013-11-07
Hello Experts,
this might be the easiest question ever asked, anyway, this is what i am trying to do. any help is highly appreciated.
i am trying to display all the item numbers ordered by user in the thank you page. and thats where i am stuck
i have literal called lItemNo (   <asp:Literal ID="lItemNo" runat="server"></asp:Literal>)
in the thank you page and in the code behind i am getting the item numbers of a order like below
            this.lItemNo.Text = Convert.ToString(HttpContext.Current.Items["OrdItem"]);
and i am getting the OrdItem from the purchase page like below
            HttpContext.Current.Items.Add("OrdItem", Basket.Order.Items[0].ItemNumber);
right nowi it works but if i have more than one item in the orde, only th first item number is being displayed
how can i change my code so that all the item numbers ordered are displayed
Thanks a lot i appreciate it.



0
Comment
Question by:niceoneishere
  • 6
  • 2
8 Comments
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 22761300
What kind of object is Basket?

I'm assuming the order items are coming form a SQL query, so I think we'd need to see your query to find the problem.
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 22761337
Hello Sir,
this is my basket
public static class Basket
{
    public const string REQ_BASKET_ID = "r_basket";

    public static Order Order { get; }

    public static void Clear();
    public static string Save();
}

and Order is as follows
public class Order
{
    public static string TESTTITLE;

    public Order();
    public Order(DataRow orderRow);
    public Order(int orderId);

    public Billing Billing { get; set; }
    public string ContactOption { get; set; }
    public string Email { get; set; }
    public string EmailContact { get; set; }
    public string GiftMessage { get; set; }
    public int Id { get; }
    public bool IsGift { get; set; }
    public Item[] Items { get; }
    public string PromotionCode { get; set; }
    public Shipping Shipping { get; }
    public Order.OrderStatusType Status { get; }
    public double Subtotal { get; }
    public double TotalCost { get; }

    public void AddItem(Item item);
    public void Purchase();
    public void RemoveItem(int itemId);
   

    public enum OrderStatusType
    {
        Basket = 0,
        Puchased = 1,
        Processed = 2,
    }
Thanks i appreciate it
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 22761448
Ok, now it makes a little more sense, so it isn't a query/datasource,  the order items are part of the Order class.

Can I see the code that populates the Literal? I'm assuming your looping/enumerating through all the order items to populate the Literal control.  I think the loop is really enumerating all the order items, unless Order is missing the items when Order is populated.

0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 22761458
Oops last sentence should read:
 I think the loop ISN'T really enumerating all the order items, unless Order is missing the items when Order is populated.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:niceoneishere
ID: 22761583
ok in the purchase.aspx i am doing this
 if ( Basket.Order.Items.Length == 0 )
            {
                Basket.Clear( );
                Response.Redirect( string.Concat(
                    ConfigurationManager.AppSettings[ "HTTPDirectory" ],
                    "viewcart.aspx?sto=true" ) );
            }

            Basket.Order.Purchase( );
           // displaying the order details like order total and item no
            // in the thank you page
            HttpContext.Current.Items.Add( "OrderId", Basket.Order.Id );
           
            HttpContext.Current.Items.Add("OrdTotal", Basket.Order.TotalCost);
            HttpContext.Current.Items.Add("OrdItem", Basket.Order.Items[0].ItemNumber);

then in the thank you page.
<div class="ordernumber">Your confirmation code is <asp:literal id="lOrderId" runat="server" />
             <asp:Literal ID="lItemNo" runat="server"></asp:Literal>
                <asp:Literal ID="lItemTot" runat="server"></asp:Literal>
                </div>
and the code behind of thank you page
 protected void Page_Load(object sender, EventArgs e)
    {
        if ( !this.IsPostBack )
        {
              this.lOrderId.Text = Convert.ToString( HttpContext.Current.Items[ "OrderId" ] );
            this.lItemNo.Text = Convert.ToString(HttpContext.Current.Items["OrdItem"]);
            this.lItemTot.Text = Convert.ToString(HttpContext.Current.Items["OrdTotal"]);
           
                    }
    }

Thanks
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 22762159
Change your code behind to loop through the order items:

protected void Page_Load(object sender, EventArgs e)
    {
        if ( !this.IsPostBack )
        {
            this.lOrderId.Text = Convert.ToString( HttpContext.Current.Items[ "OrderId" ] );
            this.lItemNo.Text = Convert.ToString(HttpContext.Current.Items["OrdItem"]);
            this.lItemTot.Text = Convert.ToString(HttpContext.Current.Items["OrdTotal"]);
            for(int i =0;i<Basket.Order.Items.Length;i++)
            {
                        ItemNo.Text += " <br/>" + Basket.Order.Items["OrdItem"][i].ToString();
                        ItemNo.Text += " <br/>" + Basket.Order.Items["OrdTotal"][i].ToString() + "<br />";
            }
        }
    }
0
 
LVL 14

Accepted Solution

by:
CtrlAltDl earned 500 total points
ID: 22762175
Oops, I was adding OrdItem and OrdTotal twice.

Try this:

protected void Page_Load(object sender, EventArgs e)
    {
        if ( !this.IsPostBack )
        {
            this.lOrderId.Text = Convert.ToString( HttpContext.Current.Items[ "OrderId" ] );

            for(int i =0;i<Basket.Order.Items.Length;i++)
            {
                        ItemNo.Text += " <br/>" + Basket.Order.Items["OrdItem"][i].ToString();
                        ItemNo.Text += " <br/>" + Basket.Order.Items["OrdTotal"][i].ToString() + "<br />";
            }
        }
    }
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 22762250
You do realize that HttpContext.Current only exists for the lifetime of a single request.  Are you sure you shouldn't be using Session variables that last during the visitors whole visit to your web app?
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now