转发器中的动态下拉列表,ASP.NET

发布于 2024-11-18 08:42:53 字数 940 浏览 1 评论 0原文

基本上,我的代码来自这里: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南风几经秋 2024-11-25 08:42:53

问题是您需要先填充 DropDownList 可能的选项,然后再设置要尝试与 Eval 内联的选定值。我会将其切换为使用 DropDownListOnDataBinding 并执行您需要的操作。

例子:

<asp:DropDownList ID="ddlName" runat="server" OnDataBinding="ddlName_DataBinding" />

protected void ddlName_DataBinding(object sender, System.EventArgs e)
{
    DropDownList ddl = (DropDownList)(sender);

    // Fill your ddl here (eg. ddl.Items.Add("abc", xyz");
    // Make sure the value you are going to set the selected item to has been added

    // Now set the selected value since it will now exist.
    ddl.SelectedValue = Eval("ddl").ToString(); 
}

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 the Eval. I would switch it to use the OnDataBinding of the DropDownList and do what you need there.

Example:

<asp:DropDownList ID="ddlName" runat="server" OnDataBinding="ddlName_DataBinding" />

protected void ddlName_DataBinding(object sender, System.EventArgs e)
{
    DropDownList ddl = (DropDownList)(sender);

    // Fill your ddl here (eg. ddl.Items.Add("abc", xyz");
    // Make sure the value you are going to set the selected item to has been added

    // Now set the selected value since it will now exist.
    ddl.SelectedValue = Eval("ddl").ToString(); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文