我已将 DropDownList 控件添加到 DetailsView,并试图让它绑定(bind)到我的更新/插入方法的“状态”参数。
<InsertItemTemplate>
<asp:DropDownList ID="States" runat="server" SelectedValue='<%# Bind("State") %>'>
<asp:ListItem Value="NY">New York</asp:ListItem>
....
</asp:DropDownList>
</InsertItemTemplate>
我已经用 50 个状态填充了 DropDownList,因此它们不绑定(bind)到任何表并且是静态项。我只是希望能够在编辑时选择一个状态,当我点击编辑时,它应该运行存储过程来编辑并将 DropDownList 的值作为@State 的参数。
不幸的是,我得到了这个错误:
'States' has a SelectedValue which is invalid because it does not exist in the
list of items.
Parameter name: value
我研究了这个问题,但一些帖子建议使用“Eval”而不是“Bind”或添加一些空值,但这并没有解决我的问题。你们对我如何摆脱这个错误有什么想法/建议吗?
最佳答案
如果 ListItems 是静态的(即在标记中定义),我相信您也应该发布它们。 请记住 ListItems 的正确语法是
<asp:ListItem Value="value" Text="displayText"></asp:ListItem>
关于c# - DetailsView 中的下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6536300/