Solved

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

Posted on 2008-10-20
8
186 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
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…

623 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