Solved

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

Posted on 2008-10-20
8
178 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
Please explain "Multi-Tenant Services" 5 60
System.Speech 2 9
C# MVC and a global static factory that never dies 4 45
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

919 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

13 Experts available now in Live!

Get 1:1 Help Now