【问题标题】:How do I bind a DropDownList to generic list inside a FormView bound to an ObjectDataSource?如何将 DropDownList 绑定到绑定到 ObjectDataSource 的 FormView 内的通用列表?
【发布时间】:2013-04-04 19:31:46
【问题描述】:

我有一个仅在编辑模式下使用的 FormView,绑定到从自定义类中选择的 ObjectDataSource。该自定义类的属性是我想绑定到表单视图中的 DropDownList 的其他对象的通用列表。

显然这不起作用,因为您不能以声明方式设置 DataSource:

<asp:DropDownList ID="ddl" runat="server" DataSource="theList">

我曾考虑在 ObjectDataSource 的 Selected 事件内的代码中绑定 DropDownLists,但 FormView 未绑定,因此我无权访问 DropDownLists。

我是否可以直接访问在 DropDownList 的 DataBound 事件中选择的 ObjectDataSource 对象?如果是这样,我如何获得那个对象。

或者,有没有更好的方法来做到这一点?

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    你试过formView的DataBound吗?

    【讨论】:

    • 嗯,不,我确定我可以在其中绑定 DropDownList,或者在 DropDownList 的 Init 或 DataBound 事件中绑定,但是我可以轻松访问 ObjectDataSource 中的数据吗?例如:在 ObjectDataSource 的选定事件中,我可以通过将 ObjectDataSourceStatusEventArgs 参数转换为我的对象类名称来评估数据,例如:object o = (ClassName)e.ResultValue。有没有办法在 DropDownList DataBound 事件中解决这个问题?
    猜你喜欢
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 2011-12-04
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    相关资源
    最近更新 更多