What you can do is before setting the datasource in the NeedDataSource event, you can check the returned data, see if it has more than one projects. If only one is available, bind Project details to Grid instead of the Projects.
If you remove the static columns and allow the Grid to generate its columns automatically, it will display the Grid with the columns and records from the Project Details instead of showing the column of Projects.
I am not entirely sure what you mean by "bind Project details to Grid instead of the Projects". Do you mean bind detail table right away? Do you have an example, please?
Thank you
Attila Antal
Telerik team
commented on 04 Jul 2023, 10:35 AM
| edited
Hi David,
The following is the code to represent the idea I shared earlier:
ProtectedSub RadGrid1_NeedDataSource(sender AsObject, e As GridNeedDataSourceEventArgs)
Dim dataSource As DataTable = New DataTable()
'code to fetch data from the database e.g. SELECT * FROM Projects
dataSource = ProjectsResults
If projects.Rows.Count = 1ThenDim projectId AsInteger = projects.Rows(0)("ProjectID")
'fetch the results from the ProjectDetails, e.g. SELECT * FROM ProjectDetails WHERE ProjectID = projectId
dataSource = ProjectDetailsResult
EndIf'Set the final results to the Grid (it will either be Projects or ProjectDetails)
CType(sender, RadGrid).DataSource = dataSource
EndSub
Note: the code is not complete, it only represents the idea. You can use this idea and implement the complete code that will work for your project.
As this scenario is rather specific to your requirements, we do not have an example to share. You can review my idea and implement a custom functionality based on that.