我有一个产品订单审核页面,其中显示了用户输入的内容列表。我们需要的是每个产品或产品分组所属的位置名称(即如果用户从“服务台”列表中选择了3个产品,那么这三个产品应显示在订单审核页面的“服务台”标题下。如果用户从“Lobbies”列表中购买了5个商品,则这5个商品应显示在订单审核页面的“Lobbies”标题下。
目前,我可以获得正确的标题文本,但文本会在每个项目中重复出现(即标题“书桌”出现在“书桌”列表中订购的3个项目的每一个上方)。我希望每个项目/组合项目只出现一次,但我不知道该怎么做。
我正在使用转发器向用户显示订单信息,其他所有内容都按照我想要的方式运行。只是这一点我很困惑。任何帮助都会很棒。提前谢谢!
以下是设计师代码:
<asp:Repeater ID="orderRepeater" runat="server" >
<itemtemplate>
<h3 class="locationName"><%# Eval("LocationName") %></h3>
<div class="headerRow">
<div class="header">
<div class="thumb"><p></p></div>
<div class="headerField name"><p class="hField">Product</p></div>
<div class="headerField sku"><p class="hField">GOJO SKU</p></div>
<div class="headerField size"><p class="hField">Size</p></div>
<div class="headerField case"><p class="hField">Case Pack</p></div>
<div class="headerField qty"><p class="hField">Quantity</p></div>
</div>
</div>
<div class="table">
<div class="row">
<div class="thumb"><%# Eval("Thumbnail") %></div>
<div class="field name"><p class="pField"> <%#Eval("ProductName") %> </p></div>
<div class="field sku"><p class="pField"> <%#Eval("Sku") %></p></div>
<div class="field size"><p class="pField"> <%#Eval("Size") %></p></div>
<div class="field case"><p class="pField"><%#Eval("CasePack") %></p></div>
<div class="field qty"><p class="pField"><%#Eval("Qty") %></p></div>
</div>
</div>
</itemtemplate>
</asp:Repeater>
这是背后的代码:
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 && 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"] = "<image src=\"" + ScHelper.GetCorrectFilePath(fileField) + "\" border=\"0\" alt=\"\">";
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: ";
}
}
答案 0 :(得分:1)
我将标题放在<HeaderTemplate>
中。所以它看起来像:
<asp:Repeater ID="orderRepeater" runat="server" >
<HeaderTemplate><h3><asp:Literal runat="server" id="header" /></h3></HeaderTemplate>
<ItemTemplate>[your existing code here]</ItemTemplate>
</asp:Repeater>
在代码背后做了类似的事情:
protected void orderRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
((Literal)e.Item.FindControl("header")).Text = "The header" // Whatever you would like this to be;
}
}