asp.net列表框格式在回发后不持久
本文关键字:不持久 格式 net 列表 asp | 更新日期: 2023-09-27 18:02:37
我有一个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
MarkIncompleteList ();
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);
}
}
很抱歉这个愚蠢的问题,感谢大家的快速回复。这个问题与清单上的项目有关。我没有在选择后清理项目。这使我的列表看起来很正常,但在原始列表的末尾重新添加了格式化的列表。我已经纠正了这个错误,现在可以正常工作了。
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);
}
}