我有一个DropDownList正在从数据集中获取数据, 下拉列表显示数据集中的所有数据完美, 但我想向列表添加一个空值作为默认选定值。 我该怎么做?DropDownList数据源+空值
0
A
回答
3
你可以做这样的事情:
ActionsMenu.DataSource = myDataSource;
ActionsMenu.DataTextField = "value";
ActionsMenu.DataValueField = "key";
ActionsMenu.DataBind();
// after the binding
ActionsMenu.Items.Insert(0, new ListItem("Select an action...", String.Empty));
ActionsMenu.Items.Insert(1, new ListItem("-------------------", String.Empty));
d。
+0
嗨Dibier,你能帮我http://stackoverflow.com/questions/20227570/dropdownlist-inside-edititemtemplate –
0
你可以这样来做:
dropdownlist.Items.Insert(0, new ListItem(0, "< Select an option >"))
0
的选项有:
- 将它添加到您的数据表
- 在页面生命周期中的数据绑定事件之后添加它已经完成。
- 使用javascript或jquery将其添加到客户端。
2
在您绑定列表后,您可以使用插入。
实施例:
LISTNAME.Items.Insert(0, new ListItem("Text", "Value"));
的0告诉它在列表的第一点去。
相关问题
- 1. 带数据源设置和空值的Dropdownlist?
- 2. Dropdownlist返回空值
- 3. 与参数化数据源绑定DROPDOWNLIST不守值回传
- 4. 空数据源
- 5. 将DropDownList数据源绑定到XPathSelect
- 6. .NET对象数据源,DetailsView和DropDownList
- 7. 的AutoPostBack = “真” 的DropDownList的数据源与
- 8. 更改DropdownList数据源动态
- 9. gridview中的dropdownlist空值
- 10. 回发时DropDownList值为空
- 11. ASP.NET DropDownList绑定到数据但允许空值?
- 12. yii dropDownList使用Javascript发布空值动态填充数据
- 13. Asp.net DropdownList源有值,但抛出空异常
- 14. DataGridViewComboBoxCell数据源空
- 15. DropDownList不填充数据来自数据源
- 16. DropDownList的值=“”没有被从数据库
- 17. 如何让YUI数据源解析数据集中的空值?
- 18. 如果选中的值不在源中,DropDownList将显示空白值
- 19. GridView和空数据源
- 20. Datagridview数据源为空
- 21. 数据源的DataGridView是空
- 22. 以空值,而在DropDownList中的MVC 3
- 23. ASP.NET GridView控件DropDownList的帖子空值
- 24. DropDownList的初始值应为空
- 25. DROPDOWNLIST填充抛出错误与空值
- 26. 如何将Page.FindControl Dropdownlist从数据源分配到N层数组
- 27. Asp.Net C#如何将空值参数传递给数据源
- 28. C#的DropDownList上市数值
- 29. 剑道DropDownList的速度太慢,而读取数据源
- 30. 绑定的DropDownList到DetailsView控件没有数据源
取决于你的数据源对象是什么。你用什么作为数据源? – Connell