如何绑定中继器内的下拉列表?
我想绑定中继器内的下拉列表。我的代码是
<asp:Repeater ID="rep_UnAssignComps" runat="server">
<ItemTemplate><asp:DropDownList ID="drp_CompPropAddress" runat="server">
</asp:DropDownList></itemTemplate></asp:Repeater>
I want to bind dropdownlist which is inside a repeater.my code is
<asp:Repeater ID="rep_UnAssignComps" runat="server">
<ItemTemplate><asp:DropDownList ID="drp_CompPropAddress" runat="server">
</asp:DropDownList></itemTemplate></asp:Repeater>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 Repeater 的
ItemDatabound
事件中使用以下内容:On your Repeater's
ItemDatabound
event use the following:使用 Repeater 的 ItemDataBound 事件,如下所示:
还记得在标记或 ItemDataBound 事件中设置 DataTextField 和 DataValueField 属性。
Use the ItemDataBound event of the Repeater, like this:
Also remember to set the DataTextField and DataValueField properties, either in the markup or in the ItemDataBound event.
我刚刚找到了一种以声明方式执行此操作的方法:
Eval() 中使用的“地址”是绑定到使用后面的代码完成的转发器的类的成员。在我的例子中,用作 MyList 的数据源是一个列表,其中包含将显示在下拉列表中的可能值。
I just found a way to do this declaratively:
The "Address" used in the Eval() is a member of the class that is bound to the repeater done using the code behind. The DataSource used as MyList is a List in my case, that contains the possible values that will show up in the dropdown.
使用 Repeater 的 OnItemCreated 事件并绑定其中的下拉菜单。
HTML
隐藏代码:
Use Repeater's
OnItemCreated
event and bind the dropdowns inside it.HTML
Codebehind:
使用此代码
并在代码隐藏中:
来自 https://www.aspsnippets.com/Articles/Populate-Bind-DropDownList-in-ItemTemplate-of-Repeater-Control-in-ASPNet.aspx
use this
and in codebehind:
from https://www.aspsnippets.com/Articles/Populate-Bind-DropDownList-in-ItemTemplate-of-Repeater-Control-in-ASPNet.aspx