我的项目中有一个BulletedList控件。我想将BulletedList控件的所有项都赋给一个数组变量。
BulletedList中有3个项目。
string[] array = new string[3];
array = blistselected.Items.Value;我该怎么做呢?
谢谢。
发布于 2011-08-23 19:18:55
只需使用for或foreach遍历Items集合,如下所示。
string listCount = blistselected.Items.Count;
string[] array = new string[listCount];
for (int i=0; i<blistselected.Items.Count; i++)
{
array[i] = blistselected.Items[i].Text;
}发布于 2011-08-23 19:18:08
你需要ListItemCollection.CopyTo() method。
因此它将是:
string[] array = new string[3];
blistselected.Items.CopyTo(array, 0);我纯粹是通过查看文档来做到这一点的,所以可能需要更改和类型转换等。
此外,由于有3个项目,您的数组有一个额外的元素。
https://stackoverflow.com/questions/7160122
复制相似问题