I have a query that returns a couple of tables where @ClientID is passed - shortened here for the example.
Table 1 (Master Sales Records - tblSales) - ID, dtSale, Client_ID
Table 2 (Detail Sales Records - tblSalesDetails) - ID, Sale_ID, Item_Name
In the database, the foreign key is tblSales.ID to tblSalesDetails.Sale_ID -- this is not specified in my query. They are two unjoined tables.
In the grid, I need two bands. BAND 0 - should be Table 1 (parent). BAND 1 should be the child rows of BAND 0 and contain all detail rows that pertain to the row in BAND 0.
I have a stored procedure set up in entity framework that returns a result set. The line of code in VB.NET works fine as follows (single band)
gridPurchases.DataSource = MyContext.uspGetClientPurchases(objClient.ID).ToList
How do I get the other child table to work as the 2nd band on the grid? The whole project is using Entity Framework so I've been trying to avoid the older way with the .NET Dataset.
Can anyone help? I've been stuck on this all day.
Thank you!
Hi,
The grid only has one DataSource. There's no way to specify a second data source for the child band. So the DataSource you assign to the grid has to contain the proper structure of parent and child rows. So if you are retrieving the data as two separate, unrelated tables, then that will not display in the grid by simply assigning a DataSource.
There are a couple of approaches you could take here.
The best thing to do is to create a data source that has all of the bound information you need. I'm not an expert on the EntityFramework, but what would have to happen is that each row in the parent list would have to have a public property which returns a List (IList) or preferably an IBindingList which is a much better interface for binding.
If that's not possible, then another approach would be to use some sort of intermediary object as the grid's DataSource. The UltraDataSource component is ideal for this purpose. So you would create an UltraDataSource and set it up with the parent and child band and the columns you want in the grid. Then you would bind the grid to the UltraDataSource. In addition, you would either have to copy your data from the EntityFramework into the UltraDataSource, or more likely, handle the events of the UltraDataSource such as CellDataRequested and essentially use it to get the data on-demand.
This second approach requires a lot more coding, of course, so personally, I would take the first approach where your data source just includes the proper structure up-front.