我已将标签文本设置为空,因为它取决于具体情况。 在ascx文件中,我设置如下代码:
<td runat="server" id="tdAvailableD" class="text-center" style ="font-size: 12px">
<asp:Label ID="lblAvailable" runat="server" ForeColor="Red" Visible="true" Text=""></asp:Label></td>
在ascx.cs文件中,我设置如下代码:
private void CheckQuantityError()
{
for (int i = 0; i < dlDiscountedProducts.Items.Count; i++)
{
{
DropDownList qty = (DropDownList)dlDiscountedProducts.Items[i].FindControl("ddlQuantity");
HiddenField productId = (HiddenField)dlDiscountedProducts.Items[i].FindControl("hdnProductID");
HiddenField discountRuleId = (HiddenField)dlDiscountedProducts.Items[i].FindControl("hdnDiscountRuleId");
//HiddenField AvailStatus = (HiddenField)dlDiscountedProducts.Items[i].FindControl("hdnAvailStatus");
//HtmlGenericControl spanAvailStatus = (HtmlGenericControl)dlDiscountedProducts.Items[i].FindControl("spanAvailStatus");
Label lblOutofStockError = (Label)dlDiscountedProducts.Items[i].FindControl("lblOutofStockError");
Label lblAvailable = (Label)dlDiscountedProducts.Items[i].FindControl("lblAvailable");
DCShoppingCartItem shoppingCartItem = new DCShoppingCartItem();
if (null != Product)
{
bool status = false;
try
{
using (new AcsServiceContextScope())
{
status = AcsServiceContextScope.Current.Products.GetAxStockAvailability(new GetStockAvailabilityRequest()
{
ModelNumber = Product.ModelNumber,
Quantity = 1,
ProductId = Product.Id
}).StockStatus;
}
}
catch (Exception ex)
{
Logging.EventLogger.LogEvent(ex);
}
if (status == true)
{
//spanAvailStatus.Attributes["class"] = "glyphicon glyphicon-remove";//available
lblAvailable.Visible = true;
lblAvailable.Text = "In Stock";
lblOutofStockError.Visible = true;
lblAlert.Visible = true;
}
else
{
//spanAvailStatus.Attributes["class"] = "glyphicon glyphicon-ok";//not available
lblAvailable.Visible = true;
lblAvailable.Text = "No Stock";
lblOutofStockError.Visible = true;
lblAlert.Visible = true;
//qty.BackColor = System.Drawing.Color.Yellow;
}
}
}
}
}
但是文字没有显示在页面中。功能应该显示,如果该项目有数量,那么它将显示在库存中。
答案 0 :(得分:0)
尝试在更新面板中保留lblAvailable
,然后尝试回发页面。
原因可能是设置标签中的文字没有回发到页面。
答案 1 :(得分:0)
检查值是否正确到达lblAvailable
。
如果是?
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<td runat="server" id="tdAvailableD" class="text-center" style ="font-size: 12px">
<asp:Label ID="lblAvailable" runat="server" ForeColor="Red" Visible="true" Text=""></asp:Label></td>
</ContentTemplate>
</asp:UpdatePanel>
然后在.cs
中使用此
UpdatePanel.Update();
并删除Text
和ForeColor
属性,而不是.cs
你甚至可以给出不同的颜色
lblAvailable.ForeColor = System.Drawing.Color.Green;//or red when not in stock