【发布时间】:2011-06-30 14:24:00
【问题描述】:
我已经向 DetailsView 添加了一个 DropDownList 控件,并且我试图让它绑定到我的更新/插入方法的“状态”参数。
<InsertItemTemplate>
<asp:DropDownList ID="States" runat="server" SelectedValue='<%# Bind("State") %>'>
<asp:ListItem Value="NY">New York</asp:ListItem>
....
</asp:DropDownList>
</InsertItemTemplate>
我已经用 50 个状态填充了 DropDownList,因此它们没有绑定到任何表并且是静态项。我只是希望能够在编辑时选择一个状态,当我点击编辑时,它应该运行存储过程进行编辑并将 DropDownList 的值作为@State 的参数。
很遗憾,我收到了这个错误:
'States' has a SelectedValue which is invalid because it does not exist in the
list of items.
Parameter name: value
我研究了这个问题,但一些帖子建议使用“Eval”而不是“Bind”或添加一些空值,但这并没有解决我的问题。你们对我如何摆脱这个错误有任何想法/建议吗?
【问题讨论】:
-
when I hit edit你不应该看EditTemplate吗? -
是的,我的意思是在你填写EditTemplate之后,然后你点击更新按钮,它应该会更新。