Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-20
8
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 
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
 
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 1500 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

688 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