转发器中的动态下拉列表,ASP.NET
基本上,我的代码来自这里: http://ranafaisal.wordpress.com/2009/02/17/dynamically-adding-removing-textboxes-in-aspnet-repeater/
但是,问题是,我需要带有文本框的下拉列表。拥有下拉列表的目的是允许用户选择他们的原籍国。他们可以选择添加或删除之前输入的详细信息。
这是我的错误消息:
'ddlName' 的 SelectedValue 是 无效,因为它不存在于 项目清单。参数名称: 值
这是我在 Default.aspx 中的 repeater 内的 dropdownlist 代码
<asp:DropDownList ID="ddlName" runat="server" SelectedValue='<%# DataBinder.Eval(Container.DataItem, "ddl") %>'></asp:DropDownList>
后面的代码与我提供的链接完全相同。
- 需要注意的点: 不涉及数据库。
请不要告诉我谷歌或其他任何东西,因为我过去几个小时一直在谷歌搜索,但没有结果。我肯定已经用谷歌搜索了足够多的内容,并在在这里发布之前尝试了其他人给出的解决方案。我几乎束手无策
对于附加组件,由于下拉列表问题,我什至无法启动我的应用程序。
Basically, the codes I have is from here : http://ranafaisal.wordpress.com/2009/02/17/dynamically-adding-removing-textboxes-in-aspnet-repeater/
However, the thing is that, I will need a dropdownlist with textboxes. The purpose of having dropdownlist is to allow users to select their country of origin. They have the option to Add or Remove the particulars they have entered before.
This is my error message:
'ddlName' has a SelectedValue which is
invalid because it does not exist in
the list of items. Parameter name:
value
This is my dropdownlist code inside a repeater in Default.aspx
<asp:DropDownList ID="ddlName" runat="server" SelectedValue='<%# DataBinder.Eval(Container.DataItem, "ddl") %>'></asp:DropDownList>
The codes behind is exactly the same as the link I provided.
- Points to note: There is no database involved.
Please not tell me to google or anything because I have been googling for the past few hours, to no avail. I definitely have googled enough, and tried the solutions given by others before posting here. I am pretty much at my wits end
To add-on, I cannot even start-up my application because of the dropdownlist problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您需要先填充
DropDownList
可能的选项,然后再设置要尝试与Eval
内联的选定值。我会将其切换为使用DropDownList
的OnDataBinding
并执行您需要的操作。例子:
The problem is you need to fill the
DropDownList
possible options before you set the selected value which you are trying to do inline with theEval
. I would switch it to use theOnDataBinding
of theDropDownList
and do what you need there.Example: