Solved

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

Posted on 2008-10-20
8
182 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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