我有以下代码。
我试图将值插入到列表框中,然后能够按字母顺序重新排序这些值并在同一列表框中重新显示它们。但出于某种原因,代码不起作用(没有错误-只是当我按按钮时列表框就被清空了)。
我试图将值插入到列表框中,然后能够按字母顺序重新排序这些值并在同一列表框中重新显示它们。但出于某种原因,代码不起作用(没有错误-只是当我按按钮时列表框就被清空了)。
protected void sortButton_Click(object sender, ImageClickEventArgs e)
{
string[] movieArray = new string [cartListBox.Items.Count];
for (int i = 0; i < cartListBox.Items.Count; i++)
{
movieArray[i] = cartListBox.Items[i].ToString();
}
Array.Sort(movieArray);
cartListBox.Items.Clear();
for (int i = 0; i < cartListBox.Items.Count; i++)
{
cartListBox.Items.Add(movieArray[i].ToString());
}
}