你能从ObjectDataSource获得一个DataTable吗?

时间:2021-12-24 03:58:18

If I have an ObjectDataSource defined at design time, can I get a DataTable from that ObjectDataSource at runtime? I have a method that returns a DataTable that I am using for the Select method property of the ObjectDataSource.

如果我在设计时定义了ObjectDataSource,我可以在运行时从该ObjectDataSource获取DataTable吗?我有一个方法返回一个DataTable,我正在使用它为ObjectDataSource的Select方法属性。

2 个解决方案

#1


I don't really understand your question... are you asking if the object you define in the ObjectDataSource can return a DataTable in the configured select method? Yes, I do it all the time. You can also examine the returned DataTable in the OnSelected event (it is the ReturnValue property of the event object).

我真的不明白你的问题......你问你在ObjectDataSource中定义的对象是否可以在配置的select方法中返回一个DataTable?是的,我一直这样做。您还可以检查OnSelected事件中返回的DataTable(它是事件对象的ReturnValue属性)。

#2


Yes, but you need to pay attention to when that item has been bound.

是的,但您需要注意该项目何时被绑定。

If you are talking about a web page:

如果您正在谈论网页:

If you tried to access the DataSource (in your case DataTable) before the page has loaded, it will be null.

如果您在页面加载之前尝试访问DataSource(在您的情况下为DataTable),则它将为null。

If you tried to access it after it has been bound, you'd be able to use the object.

如果您在绑定后尝试访问它,则可以使用该对象。

#1


I don't really understand your question... are you asking if the object you define in the ObjectDataSource can return a DataTable in the configured select method? Yes, I do it all the time. You can also examine the returned DataTable in the OnSelected event (it is the ReturnValue property of the event object).

我真的不明白你的问题......你问你在ObjectDataSource中定义的对象是否可以在配置的select方法中返回一个DataTable?是的,我一直这样做。您还可以检查OnSelected事件中返回的DataTable(它是事件对象的ReturnValue属性)。

#2


Yes, but you need to pay attention to when that item has been bound.

是的,但您需要注意该项目何时被绑定。

If you are talking about a web page:

如果您正在谈论网页:

If you tried to access the DataSource (in your case DataTable) before the page has loaded, it will be null.

如果您在页面加载之前尝试访问DataSource(在您的情况下为DataTable),则它将为null。

If you tried to access it after it has been bound, you'd be able to use the object.

如果您在绑定后尝试访问它,则可以使用该对象。