title: Display a header for each grouping of items in a repeater?
body: <p>I have an product order review page that displays a list of whatever the user has entered. What is needed is the name of the location that each product or product grouping belongs to (i.e. If the user selected 3 products from under the "Desks" listing, those three products should appear under the header "Desks" on the order review page. If the user purchased 5 items from under the "Lobbies" listing, then those 5 products should appear under the header "Lobbies" on the order review page).</p>
  
  <p>Currently, I can get the correct header text, but the text repeats itself with each item (i.e. The header "Desks" appears above each of the 3 items ordered under the "Desks" listing). I would like it to appear only once per item/grouping of items but I am not sure how to do it.</p>
  
  <p>I am using a repeater to display the order information to the user, and everything else is working the way I want it. It's just this little bit I'm confused about. Any help would be great. Thanks in advance!</p>
  
  <p>Here is the designer code:</p>
  
  <pre><code>&lt;asp:Repeater ID="orderRepeater" runat="server" &gt;
      &lt;itemtemplate&gt;
          &lt;h3 class="locationName"&gt;&lt;%# Eval("LocationName") %&gt;&lt;/h3&gt;
          &lt;div class="headerRow"&gt;
              &lt;div class="header"&gt;
                  &lt;div class="thumb"&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;
                  &lt;div class="headerField name"&gt;&lt;p class="hField"&gt;Product&lt;/p&gt;&lt;/div&gt;
                  &lt;div class="headerField sku"&gt;&lt;p class="hField"&gt;GOJO SKU&lt;/p&gt;&lt;/div&gt;
                  &lt;div class="headerField size"&gt;&lt;p class="hField"&gt;Size&lt;/p&gt;&lt;/div&gt;
                  &lt;div class="headerField case"&gt;&lt;p class="hField"&gt;Case Pack&lt;/p&gt;&lt;/div&gt;
                  &lt;div class="headerField qty"&gt;&lt;p class="hField"&gt;Quantity&lt;/p&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="table"&gt;
              &lt;div class="row"&gt;
                  &lt;div class="thumb"&gt;&lt;%# Eval("Thumbnail") %&gt;&lt;/div&gt;
                  &lt;div class="field name"&gt;&lt;p class="pField"&gt; &lt;%#Eval("ProductName") %&gt; &lt;/p&gt;&lt;/div&gt;
                  &lt;div class="field sku"&gt;&lt;p class="pField"&gt; &lt;%#Eval("Sku") %&gt;&lt;/p&gt;&lt;/div&gt;
                  &lt;div class="field size"&gt;&lt;p class="pField"&gt; &lt;%#Eval("Size") %&gt;&lt;/p&gt;&lt;/div&gt;
                  &lt;div class="field case"&gt;&lt;p class="pField"&gt;&lt;%#Eval("CasePack") %&gt;&lt;/p&gt;&lt;/div&gt;
                  &lt;div class="field qty"&gt;&lt;p class="pField"&gt;&lt;%#Eval("Qty") %&gt;&lt;/p&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/itemtemplate&gt;
  &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>Here is the code behind:</p>
  
  <pre><code>private void Page_Load(object sender, EventArgs e) 
  {
      Label lbl = (Label)FindControl("orderLbl");
      Item CurrentItem = Sitecore.Context.Item;
      Item HomeItem = ScHelper.FindAncestor(CurrentItem, "gojoMarket");
  
      if (Session["orderComplete"] != null &amp;&amp; Session["orderComplete"] != "")
      {
  
          if (HomeItem != null)
          {
              Item ProductGroup = HomeItem.Axes.SelectSingleItem(@"child::*[@@templatename='gojoMarketOfficeBuildigProductMap']/*[@@templatename='gojoOrderReview']");
  
              Database db = Sitecore.Context.Database;
              DataSet dset = new DataSet();
  
  
              if (ProductGroup != null)
              {
                  string InFromSession = Session["orderComplete"].ToString();
  
                  try
                  {
                      DataTable summary = dset.Tables.Add("summary");
  
                      summary.Columns.Add("LocationName", Type.GetType("System.String"));
                      summary.Columns.Add("Thumbnail", Type.GetType("System.String"));
                      summary.Columns.Add("ProductName", Type.GetType("System.String"));
                      summary.Columns.Add("Sku", Type.GetType("System.String"));
                      summary.Columns.Add("Size", Type.GetType("System.String"));
                      summary.Columns.Add("CasePack", Type.GetType("System.String"));
                      summary.Columns.Add("Qty", Type.GetType("System.String"));
                      summary.Columns.Add("Location", Type.GetType("System.String"));
  
                      Label qL = (Label)FindControl("qty");
                      string[] orders = InFromSession.Split(';');
                      foreach (string order in orders)
                      {
                          int total = orders.GetUpperBound(0);
                          if (order != "")
                          { 
                              string[] infos = order.Split(',');
  
                              string ids = infos.GetValue(0).ToString();
  
                              string qtys = infos.GetValue(1).ToString();
  
                              if (ids != "")
                              {
                                  Item CatalogueItem = db.Items[ids];
                                  DataRow drow = summary.NewRow();
  
                                  Item LocationItem =  ScHelper.FindAncestor(CatalogueItem, "gojoProductLocation");
                                  if (LocationItem != null)
                                  {
                                      //this returns the header text values that I need
                                      string LocationName = LocationItem.Fields["Header"].ToString();
  
                                      drow["LocationName"] = LocationName;
                                  }
                                      Item orderItem = db.Items[CatalogueItem.Fields["Reference SKU"].Value];
                                      if (orderItem != null)
                                      {
                                          Item marketItem = db.Items[orderItem.Fields["Master Product"].Value];
                                          if (marketItem != null) 
                                          {
                                              Item CPNItem = db.Items[marketItem.Fields["Complete Product Name"].Value];
  
                                              drow["Thumbnail"] = "";
  
                                              Sitecore.Data.Fields.XmlField fileField = marketItem.Fields["Thumbnail"];
                                              drow["Thumbnail"] = "&lt;image src=\"" + ScHelper.GetCorrectFilePath(fileField) + "\" border=\"0\" alt=\"\"&gt;";
  
                                              if (CPNItem != null)
                                              {
                                                  var name = CPNItem["Complete Name"];
                                                  drow["ProductName"] = name;
                                              }
  
                                              drow["Sku"] = marketItem.Fields["SKU"].Value;
                                              drow["CasePack"] = marketItem.Fields["Case Pack"].Value;
                                              if (marketItem.Fields["Size"] != null)
                                              {
                                                  drow["Size"] = marketItem.Fields["Size"].Value;
                                              }
                                              else
                                              {
                                                  drow["Size"] = "N/A";
  
                                              }
  
                                              drow["Qty"] = qtys.ToString();
                                              summary.Rows.Add(drow);
                                          }
                                      }
  
  
  
                               }
  
                          }
                      }
                      orderRepeater.DataSource = dset;
                      orderRepeater.DataMember = "summary";
                      orderRepeater.DataBind();
                  }
                  catch (Exception x)
                  {
                      Response.Write(x.Message.ToString());
  
                  }
              }
  
          }
      }
      else
      {
          HyperLink none = (HyperLink)FindControl("link");
          Label msg = (Label)FindControl("msgLbl");
          none.Visible = true;
  
          msg.Text = "You have not selected any items for purchase. To purchase items, please visit our complete product listing: ";
      }
  }
  </code></pre>