我有一个ListBox,它根据状态突出显示了项目。如果它们不完整,则为红色。从列表中选择一个项目并显示它的相关数据后,着色不起作用。如何保持此格式不变?
代码:
if (!IsPostBack)
{
MarkIncompleteList();
DataTable dt = Data.GetOrderStatusTypes();
ddlOrderStatusTypes.DataSource = dt;
ddlOrderStatusTypes.DataTextField = "StatusName";
ddlOrderStatusTypes.DataValueField = "StatusID";
ddlOrderStatusTypes.DataBind();
if (Request.QueryString["OrderID"] != "")
{
Data.GetOrderByNumber(ref currOrder, Request.QueryString["OrderID"]);
DisplayOrderData();
}
}
else
protected void MarkIncompleteList()
{
// get a list of orders that are not complete for allerting
List<string> iOrders = Data.GetIncomepletedOrders();
lbOrderID.Text = "";
List<string> ol = Data.GetOrdersList();
// add the order list to the list box change the color if its in the
// incomplete list
foreach (string s in ol)
{
if (iOrders.Contains(s))
{
lbCurrentOrders.Items.Add(s);
lbCurrentOrders.Items[lbCurrentOrders.Items.Count - 1].Attributes.Add("style", "color:red");
}
else
lbCurrentOrders.Items.Add(s);
}
}
答案 0 :(得分:1)
抱歉这个愚蠢的问题,谢谢大家的快速回复。该问题与列表中的项目有关。选择后我没有清理物品。这导致我的列表看起来正常,但重新添加格式化列表到原始列表的末尾。我已经纠正了这个问题,现在它正常运作。
protected void MarkIncompleteList()
{
// remove the old items so the list is refreshed **************
lbCurrentOrders.Items.Clear();
// get a list of orders that are not complete for allerting
List<string> iOrders = Data.GetIncomepletedOrders();
lbOrderID.Text = "";
List<string> ol = Data.GetOrdersList();
foreach (string s in ol)
{
if (iOrders.Contains(s))
{
lbCurrentOrders.Items.Add(s);
lbCurrentOrders.Items[lbCurrentOrders.Items.Count - 1].Attributes.Add("style", "color:red");
}
else
lbCurrentOrders.Items.Add(s);
}
}