我正在尝试使用数组将电影标题分配给列表框。他们在下拉列表中选择电影,然后使用C#和aspx
显示在列表框中(这不起作用) protected void addToCartImageButton_Click(object sender, ImageClickEventArgs e)
{
string [] movieNameArray = new string [10];
movieNameArray[0] = "The Advengers";
movieNameArray[1] = "Titanic";
movieNameArray[2] = "Frozen";
movieNameArray[3] = "Boy";
movieNameArray[4] = "Grown Ups";
movieNameArray[5] = "Coach Carter";
movieNameArray[6] = "More than a game";
movieNameArray[7] = "Harry Potter";
movieNameArray[8] = "Avatar";
movieNameArray[9] = "Titanic";
cartListBox.Items.Add(movieNameArray.ToString());
DropDownList3.Items.Add(movieNameArray.ToString());
}
答案 0 :(得分:2)
您可以将下拉列表绑定到数组。即而不是
DropDownList3.Items.Add(movieNameArray.ToString());
使用
DropDownList3.DataSource = movieNameArray;
DropDownList3.DataBind();