【发布时间】:2014-11-11 21:12:24
【问题描述】:
我有一个名为“BasketGrid”的 GridView,其中包含有关用户选择购买的产品的信息。我在产品选项列中添加了一个名为“EditProdOpts”的超链接,以便用户可以在完成结帐过程之前返回产品页面进行更改(如果需要,该 URL 不在数据库中,所以我无法做到) GridView 中的 HyperLinkField)。
我目前有一个功能设置,应该为超链接设置正确的 url,但它只能部分工作。目前,它将 HyperLink 的每个实例设置为 GridView 中最后一个产品的 url。不过,我不确定我错过了什么......
这是函数:
protected string BuildLink(object dataItem)
{
string ProductLink = "";
foreach (GridViewRow basketRow in BasketGrid.Rows)
{
BasketItem item = (BasketItem)dataItem;
if ((item.OrderItemType == OrderItemType.Product))
{
HyperLink optionsLink = (HyperLink)basketRow.FindControl("EditProdOpts");
if (optionsLink != null)
{
optionsLink.NavigateUrl = string.Format("~/Admin/orders/Create/CreateOrderAddProduct.aspx?Action=Edit&UID={0}&LineID={1}&ProdId={2}", _UserId, item.BasketItemId, item.ProductId);
ProductLink = optionsLink.NavigateUrl;
}
}
}
return ProductLink;
}
这是超链接在 GridView 中的位置:
<asp:TemplateField HeaderText="Item">
<HeaderStyle CssClass="columnHeader" HorizontalAlign="left" VerticalAlign="top" />
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<uc:BasketItemDetail ID="BasketItemDetail1" runat="server" BasketItem="<%# Container.DataItem %>" LinkProducts="false" /><br /><%# Container.DataItem %>
<asp:PlaceHolder ID="EditOptPanel" runat="server" Visible='<%# ShowOptionsLink(Container.DataItem) %>'>
<asp:HyperLink ID="EditProdOpts" runat="server" Text="Edit Options" NavigateUrl='<%# BuildLink(Container.DataItem) %>' />
</asp:PlaceHolder>
</ItemTemplate>
</asp:TemplateField>
【问题讨论】: