I’m trying to use an ObjectBindingSource to bind data to a gridview. The data is present in the view as a subclass as the controller, in the form of a model.
var _controller = new DataController(param1, param2);
you would access it in this manner
foreach(var Variable in _controller.DataModel.Cars)
<%: Car.Name %> ...
How can I use this DataModel.Cars as the source for the Object binding source?
I currently have
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
TypeName="Choices.ChoiceService.ChoiceCollection"
DataObjectTypeName="Choices.ChoiceService.ChoiceObject"
InsertMethod="Add" SelectMethod="AsReadOnly"/>
Insert a Select Method on DataController say GetCars this way you would do:
and then you would use:
You then set the session on the codebehind witht:
Note:There are much better ways to do this, using the session like this is really ugly, this is only an example. You probably can pick a better one from the following
list:
http://msdn.microsoft.com/en-us/library/xt50s8kz.aspx
Alternatively you can use the OnDataBinding event of the ObjectDataSource to programatically set the parameters directly on the ObjectDataSource instance.