FormView 绑定中的 DropDownList
我想将 dropdownlist 绑定到 List
, 在后面的代码中。
<asp:DropDownList ID="listCategories" runat="server" Height="20px" CssClass="CategoryDropList" SelectedValue='<%# Bind("ParentId") %>' AutoPostBack="false" Width="300px">
不使用 ObjectDataSource !
如何将其绑定到下拉列表? 在什么情况下?
另外 SelectedValue='<%# Bind("ParentId") %>'
应该可以工作! (我的意思是下拉列表绑定应该在此之前发生!)
I want to bind dropdownlist to List<MyIem>
,
in code behind.
<asp:DropDownList ID="listCategories" runat="server" Height="20px" CssClass="CategoryDropList" SelectedValue='<%# Bind("ParentId") %>' AutoPostBack="false" Width="300px">
Without using ObjectDataSource !
How can I Bind it to the dropdown list? In what event?
Also SelectedValue='<%# Bind("ParentId") %>'
should work! (I mean the dropdownlist binding should occur before this!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我面临着类似的问题。 我注意到您试图将其添加到而不是这可能是您没有看到它的主要原因。
然而,我已经研究了上面提供的两种解决方案,并发现这对我有用:-
希望这对您有帮助。
well i was facing a similar problem. i noticed that you were trying to add it to and not which can be a major cause that you did not see it.
i have however worked on both the solutions provided above and found this worked for me :-
hope this helpes you.
您可以使用另一个数据源填充 DropDownList,假设有效值位于数据库中。 观看此视频:
http://msdn.microsoft.com/en-us /data/cc546554.aspx
它使用 EntityDataSource 而不是 ObjectDataSource,但原理应该仍然有效。
如果您想要 null 的“(none)”类型选项,请参阅本页上的“在模板字段中转换 Null”部分:
http://msdn.microsoft.com/en-us/library/ms366709.aspx
具体来说:
请注意“AppendDataBoundItems”属性和“asp:ListItem”元素。
You can populate the DropDownList with another DataSource, assuming the valid values are in the database. Check out this video:
http://msdn.microsoft.com/en-us/data/cc546554.aspx
It's using an EntityDataSource instead of an ObjectDataSource, but the principle should still work.
If you want a "(none)" type option for null, see section "Converting Null in Template Fields" on this page:
http://msdn.microsoft.com/en-us/library/ms366709.aspx
Specifically:
Notice the the "AppendDataBoundItems" attribute and the "asp:ListItem" element.
制作了一个在 DataBound 事件中设置下拉列表的示例。
这是标记
使用ddl的方法是在DataBound事件期间使用findcontrol()查找它。
当您在 DataBound 事件中拥有控件时,您还可以将下拉列表绑定到您的 List<>>
希望这会有所帮助。
这是背后的代码:
Made an example which will set the dropdown in the DataBound event.
Here is the markup
The way to use the ddl, is to find it with findcontrol() during DataBound event.
When you have the control in the DataBound event, you can also bind the dropdown to your List<>
Hope this helps.
Here is the code behind: