[英]C# - ASP.NET - DropDownList in GridView - SelectedValue error
I have a gridview which looks like this: 我有一个gridview看起来像这样:
And for my column "ms_resp_team" I use a dropdownlist to allow the user to choose a certain team. 对于我的“ ms_resp_team”列,我使用一个下拉列表允许用户选择某个团队。 However when I enter in edit mode, I can't figure out how to set the selectedValue of the dropdownlist to the actual value and not to the first value of the datasource that fills the dropdownlist!
但是,当我进入编辑模式时,我无法弄清楚如何将下拉列表的selectedValue设置为实际值,而不是设置为填充下拉列表的数据源的第一个值!
See here: 看这里:
Can some1 help me with this? 有人可以帮我吗? When I set the property SelectedValue (to the DDL) that webpage is going berzerk by showing an error!
当我将属性SelectedValue设置为DDL时,该网页由于显示错误而变得疯狂!
The client side syntax for the DropDownList SelectedValue is DropDownList SelectedValue的客户端语法为
SelectedValue='<%# Bind("ValueColumnName")'
ie 即
<asp:DropDownList id="ddl" runat="server" SelectedValue='<%# Bind("ValueColumnName")' DataSource="SqlDataSource1" DataTextField="TextColumnName" DataValueField="ValueColumnName" />
Make sure you are using different quotes otherwise the interpreter will get confused. 确保使用不同的引号,否则解释器会感到困惑。 Single quotes for the control parameter value and double quotes for the Bind parameter value.
控制参数值的单引号和绑定参数值的双引号。
The DateValueField parameter must also be set otherwise you will get the following error: 还必须设置DateValueField参数,否则会出现以下错误:
'ddl' has a SelectedValue which is invalid because it does not exist in the list of items.
'ddl'的SelectedValue无效,因为它不存在于项目列表中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.