简体   繁体   English

C#-ASP.NET-GridView中的DropDownList-SelectedValue错误

[英]C# - ASP.NET - DropDownList in GridView - SelectedValue error

I have a gridview which looks like this: 我有一个gridview看起来像这样: 查看模式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.

相关问题 C#Asp.Net使用DropDownList更改GridView的数据源 - C# Asp.Net changing DataSource for GridView using DropDownList DropDownList在gridview asp.net C#中的第二次尝试时刷新 - DropDownList refresh on second attempt in gridview asp.net c# ASP.NET C#-无法从SQL数据库填充(预选择)下拉列表SelectedValue - asp.net C# - unable to get populate (preselect) the dropdownlist SelectedValue from sql database C#/ASP.NET gridview 数据绑定下拉列表索引已更改 - C#/ASP.NET gridview databind dropdownlist index changed 如何在ASP.Net C#中的GridView的EditMode中显示DropdownList? - How to show DropdownList in EditMode of GridView in ASP.Net C#? 如何使用/不使用ASP.net C#中的CodeBehind将DropDownList中的SelectedValue作为查询字符串传递给LinkBut​​ton - How to pass the SelectedValue from a DropDownList as a query string in a LinkButton with/without using CodeBehind in ASP.net C# DropDownList控件asp.net SelectedValue - DropDownList Control asp.net SelectedValue ASP.NET MVC DropDownList SelectedValue转换为ViewBag? - ASP.NET MVC DropDownList SelectedValue into a ViewBag? Gridview带有来自数据库的下拉列表,并在gridview外部添加,编辑删除按钮? ASP.NET C# - Gridview with dropdownlist from the database and outside add,edit delete buttons outside the gridview ? ASP.NET C# GridView中的DropDownList绑定到ASP.NET C#中GridView内TextBox中DropDown的选定值 - DropDownList in a GridView to bind the selected value of DropDown in TextBox inside a GridView in asp.net c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM