我有一個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