Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将DropDownList绑定到绑定到ObjectDataSource的FormView中的通用列表?_C#_Asp.net - Fatal编程技术网

C# 如何将DropDownList绑定到绑定到ObjectDataSource的FormView中的通用列表?

C# 如何将DropDownList绑定到绑定到ObjectDataSource的FormView中的通用列表?,c#,asp.net,C#,Asp.net,我有一个仅在编辑模式下使用的FormView,绑定到从自定义类中选择的ObjectDataSource。该自定义类的属性是我要绑定到formview中的DropDownList的其他对象的通用列表 显然,这不起作用,因为您无法以声明方式设置数据源: <asp:DropDownList ID="ddl" runat="server" DataSource="theList"> 我曾考虑在ObjectDataSource的Selected事件中的代码隐藏中绑定DropDownLis

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

显然,这不起作用,因为您无法以声明方式设置数据源:

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

我曾考虑在ObjectDataSource的Selected事件中的代码隐藏中绑定DropDownList,但FormView当时没有绑定,因此我无法访问DropDownList

我可以直接访问DropDownList的数据绑定事件中选择的ObjectDataSource对象吗?如果是这样的话,我怎样才能得到那个物体


或者,有没有更好的方法来实现这一点?

您尝试过formView的数据绑定吗?

没有,我确信我可以在其中绑定DropDownList,或者在DropDownList的Init或DataBound事件中绑定,但是我可以轻松访问ObjectDataSource中的数据吗?例如:在ObjectDataSource的选定事件中,我可以通过将ObjectDataSourceStatusEventArgs参数强制转换为我的对象类名来评估数据,如:object o=(ClassName)e.ResultValue。有没有办法在DropDownList数据绑定事件中实现这一点?