我有一些代碼在我的工作,使用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