Has anyone managed to get their WebGrid to pull data from an ObjectDataSource that they've created in code?
I was able to drag and drop an ObjectDataSource onto my form, configure it, hook it up to a WebGrid, and everything worked fine. Using the component breaks my application's object model, however, so I decided to create an identical ObjectDatasource in code.
I have searched the forums & knowledge base, and tried every permutation I can think of to get this thing working. I built a new ObjectDataSource object in the Page_Load event, and assigned the WebGrid's datasource in the WebGrid's InitializeDataSource event.
The result is always "No Data To Display".
I'd greatly appreciate any thoughts anyone might have about this.
Lyuba,
Thanks so much for the reply. Obviously, I hadn't worked with the ObjectDataSource before, and didn't realize it won't work outside the form's controls collection.
Adding: form1.Controls.Add(ods) did the trick.
Thanks again,
Charlie
Hi,
You can try to add to the ObjectDataSource that you built in the Page_load event, all of the properties that you see that are added to the form when you drag and drop and configure the ObjectDataSource component.Here is some sample: protected void Page_Load(object sender, EventArgs e) {
ObjectDataSource ods = new ObjectDataSource(); // People is the name of your business object ods.TypeName = "People"; ods.ID = "ObjectDataSource1"; ods.SelectMethod = "getPersons"; form1.Controls.Add(ods); UltraWebGrid1.DataSourceID = ods.ID; UltraWebGrid1.DataBind(); }
If you still see "No data to display", you should verify that the SelectMethod of the ObjectDataSource (the equivalent of getPersons from the sample), really returns you the list of objects that you expect it to. I hope this helps.
Lyuba,Infragistics