如何调用我的 int 数组类来显示我的下拉列表

本文关键字:我的 数组 显示 下拉列表 int 调用 何调用 | 更新日期: 2023-09-27 18:33:27

public static int[] ddDuration()
{
    int[] ddarray = new int[] { 1, 2, 3, 4, 5 };
    return ddarray;
}

如何在 c# 中调用我的 int 数组来调用我DropDownList中的任何页面

//and I am try to show in my DropDownList
//like that some thing
Duration dm = new Duration();
//dm.ddDuration;
//dropdduration.item.AddRang(dm.ddDuration);

如何调用我的 int 数组类来显示我的下拉列表

如果我

做对了,您正在尝试将整数数组作为项目添加到 DropDownList 中。

var collection = ddDuration();
int len = collection.length;
for(int i=0; i<len; i++){
    DropDownList1.Items.Insert(i, new ListItem(collection[i].toString(), ""));
}

Insert 的第一个参数是 Items 集合中的位置(索引),第二个参数采用 ListItem;其构造函数可以基于其内容(在本例中为字符串)构建。