我有一個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. Dropdownlist返回空值
- 5. 與參數化數據源綁定DROPDOWNLIST不守值回傳
- 6. 數據源參數綁定的dropdownlist的設置值
- 7. 空數據源
- 8. 將DropDownList數據源綁定到XPathSelect
- 9. .NET對象數據源,DetailsView和DropDownList
- 10. 更改DropdownList數據源動態
- 11. 的AutoPostBack = 「真」 的DropDownList的數據源與
- 12. 綁定DROPDOWNLIST從SQL數據源OPTGROUP
- 13. gridview中的dropdownlist空值
- 14. bind dropdownlist返回空值
- 15. GridView DropDownList,處理空值
- 16. 回發時DropDownList值爲空
- 17. yii dropDownList使用Javascript發佈空值動態填充數據
- 18. ASP.NET DropDownList綁定到數據但允許空值?
- 19. Asp.net DropdownList源有值,但拋出空異常
- 20. DataGridViewComboBoxCell數據源空
- 21. DropDownList不填充數據來自數據源
- 22. 從數據庫列填充DropDownList,使用DropDownList值來填充表?
- 23. DropDownList的值=「」沒有被從數據庫
- 24. DropDownList不顯示數據綁定值
- 25. 劍道UI DROPDOWNLIST數據的值
- 26. ComboBox空值不會複製到數據綁定數據源
- 27. 如何讓YUI數據源解析數據集中的空值?
- 28. 如果選中的值不在源中,DropDownList將顯示空白值
- 29. Sitecore 8:數據源值爲空/空的子圖層(.ascx)
- 30. GridView和空數據源
取決於你的數據源對象是什麼。你用什麼作爲數據源? – Connell