如何将值从列表框传递到空的下拉列表?

时间:2013-09-28 16:35:04

标签: c# asp.net

我有一个listbox,其中包含一些字符串......我想将这些字符串传递给空dropdownlist?可能吗?只会选择listbox中的值。

我不知道我在做什么..为此我必须使用一个我仍然感到困惑的for循环。

这是我现在的代码:

    string [] lines = new string [cartListBox.Items.Count];
    int select;

    for (int i = 0; i < lines.Length ; i++)
    {
        select = cartListBox.SelectedValue
        watchedMoviesDropDownList.Items.Add(cartListBox.Items.Count.ToString());
    }

然而,当我调试它时,它给我一个错误,说索引超出范围...... :(请帮助....!

1 个答案:

答案 0 :(得分:0)

这样做要简单得多,你不需要:

string [] lines

也不:

int select

只需使用此代码:

for (int x = 0; x < cartListBox.Items.Count; x++)
    watchedMoviesDropDownList.Items.Add(cartListBox.Items[x]);
相关问题