在中继动态DropDownList中,ASP.NET [英] Dynamic dropdownlist in repeater, ASP.NET

查看:231
本文介绍了在中继动态DropDownList中,ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,codeS我就是从这里开始:<一href=\"http://ranafaisal.word$p$pss.com/2009/02/17/dynamically-adding-removing-textboxes-in-aspnet-repeater/\" rel=\"nofollow\">http://ranafaisal.word$p$pss.com/2009/02/17/dynamically-adding-removing-textboxes-in-aspnet-repeater/

Basically, the codes I have is from here : http://ranafaisal.wordpress.com/2009/02/17/dynamically-adding-removing-textboxes-in-aspnet-repeater/

然而,事情是这样的,我需要用文本框一个DropDownList。有DropDownList的目的是让用户选择他们的原籍国。他们必须添加或删除之前,他们已经进入了细节的选项。

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.

这是我的错误信息:

ddlName'具有的SelectedValue这是
  无效的,因为它不存在
  项的列表。参数名:
  值

'ddlName' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

这是我的的DropDownList code 里面的转发Default.aspx中

<asp:DropDownList ID="ddlName" runat="server" SelectedValue='<%# DataBinder.Eval(Container.DataItem, "ddl") %>'></asp:DropDownList>

在codeS背后是完全一样的,因为我提供的链接。

The codes behind is exactly the same as the link I provided.


  • 要注意几点:有没有涉及到数据库

  • Points to note: There is no database involved.

请不要告诉我Google或任何东西,因为我一直在使用Google在过去的几个小时,都无济于事。我绝对有足够的一派,并试图在这里发帖之前,别人给的解决方案。我是pretty多在我束手无策

要附加,我甚至不能启动我的应用程序,因为DropDownList的问题。

To add-on, I cannot even start-up my application because of the dropdownlist problem.

推荐答案

问题是你需要填写的DropDownList 可能的选项设置所选的值,你是前试图做的评估内联。我将其切换到使用 OnDataBinding 的DropDownList 键,你需要那里。

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.

例如:

<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(); 
}

这篇关于在中继动态DropDownList中,ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆