我有一些代码在我的工作,使用ASP.net(我从来没有碰过),但我需要排序它。下面是我需要Dscrp排序列表框:在ASP.net排序列表框
foreach (InteractiveInfo template in ddlsource)
{
Product thisProduct = FindProduct(template.UProductId);
if (thisProduct != null)
{
ddlProducts.Items.Add(
new ListItem(
string.Format("{0} ({1})", thisProduct.Dscrp, thisProduct.UProductId),
template.UProductId.ToString(CultureInfo.InvariantCulture)));
}
}
ddlProducts.DataBind();
}
我发现这个链接:
https://gist.github.com/chartek/1655779
所以我想在最后加入这样的:
ddlProducts.Items.Sort();
但它只是给了我这个错误:
Does not contain a definition for 'Sort'
你确定这是ASP经典? '.DataBind()'和你的C#标签都让我怀疑它。 – Martha
@Martha不是100%确定,但它不是MVC。它使用aspx扩展名和aspx.cs作为文件后面的代码,所以我认为这是遗留问题。 – djblois
不,.aspx是asp.net的扩展。经典的asp只是使用.asp扩展名(并没有“后面的代码”的概念)。 – Martha