若是用 SelectedValue='<%# Bind("DepartmnetId") %>' 的繫結方式,就會產生錯誤訊息
錯誤訊息:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control這項已被列為 ASP.NET 的 bug,將於下個發佈版本將會被修復
但在修復之前,可在 ItemInserting 的事件中來指定選擇值,例如:
e.Values("DepartmentId") = CInt(CType(e.Item.FindControl("ddlDepartment"), DropDownList).SelectedValue)
延伸閱讀:
DataBinding on DropDownList's SelectedValue property not working in the InsertItemTemplate of a ListView
ASP.NET 3.5 ListView with DropDownList in InsertItemTemplate
沒有留言:
張貼留言