Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 向dropdownbox添加值不起作用_C#_Asp.net - Fatal编程技术网

C# 向dropdownbox添加值不起作用

C# 向dropdownbox添加值不起作用,c#,asp.net,C#,Asp.net,这是我的客户代码: <li>choose file: &nbsp;&nbsp;&nbsp;<asp:DropDownList id="chooseFileDropDown" runat="server" /></li> 我也尝试过: chooseFileDropDown.items.Add("Test"); 而且: List<ListItem> listItem = new List<ListItem>()

这是我的客户代码:

<li>choose file: &nbsp;&nbsp;&nbsp;<asp:DropDownList id="chooseFileDropDown" runat="server" /></li> 
我也尝试过:

chooseFileDropDown.items.Add("Test");
而且:

List<ListItem> listItem = new List<ListItem>();
listItem.Add(new ListItem("Test"));
chooseFileDropDown.Items.Add(listItem.ToString());
试试这个:

chooseFileDropDown.Items.Insert(0, new ListItem("Add New", ""));
如果要在顶部添加:

ListItem lst = new ListItem ( "Add New" , "0" );
chooseFileDropDown.Items.Insert(chooseFileDropDown.Items.Count-1 ,lst);

如果它被加载到
页面加载
中,为什么不在下拉列表中显示完整的
页面加载
?添加appendDataBounds=“true”tag@user1848739:OP没有提到他还使用了
数据源
。但是,只要我们看不到他的代码,我们只能猜测。那么,这是您添加项目或分配
数据源的唯一地方吗?是否执行了
Page\u Load
?这个
DropDownList
的上下文是什么,它是否位于另一个数据绑定的网络控件(如repeater或gridview)中,还是位于
UserControl
中?是的,当调用aspx页面时,它会被加载,我现在手动加载。现在我只需点击一个链接就可以打开这个页面,然后在页面加载时应该填充下拉框
chooseFileDropDown.Items.Insert(0, new ListItem("Add New", ""));
ListItem lst = new ListItem ( "Add New" , "0" );
chooseFileDropDown.Items.Insert(chooseFileDropDown.Items.Count-1 ,lst);