I have the following declaration in my .ASPX :
<asp:ObjectDataSource ID="ODS" runat="server"
SelectMethod="GetPlayersData" DataObjectTypeName="DAL.MyObject">
</asp:ObjectDataSource>
How can I place the data in the ObjectDataSource from the code behind ?
This :
var items = MyFunctions.GetPlayersData().ToList<object>();
ODS.SelectParameters = (ParameterCollection)items;
Doesn't work.
If I understand that you want to call
DAL.MyObject.GetPlayersData()
and get that data to a data bound control, you don't necessarily need anObjectDataSource
. You can simply wire the data into the DataSource property and then call the DataBind method:Alternatively, if you still want to use some of the features of
ObjectDataSource
to make two way data binding nicer, you can build up aObjectDataSource
programatically in your code behind. The process is very similiar to the declarative syntax:The
ObjectDataSource
will callGetPlayersData()
itself, so you don't need to call it yourself.But if for some odd reason you need to, you can override the ReturnValue in the Selected event: