Click here to Skip to main content
15,846,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a query that uses a pivot table which populates columns dynamically depending what values are passed to the query. The results from the query has the departmen for rows and CallType for the dynamic columns.

I want to simply want to put the results returned into a datagrid, but unable to because the column name can change.

Please can anyone advise?
Using C# asp.net

What I have tried:

foreach (DataRow dr in dt.Rows)
                   {
                       CallEntity callSummaryEntity = new CallEntity();
                       callSummaryEntity.Department = (string.IsNullOrEmpty(dr["DEPTNAME"].ToString())) ? string.Empty : dr["DEPTNAME"].ToString();
                       //callSummaryEntity.CallType = (string.IsNullOrEmpty(dr["CallType"].ToString())) ? string.Empty : dr["CallType"].ToString();
                       objects.Add(callSummaryEntity);

                   }
Posted

1 solution

 
Share this answer
 
Comments
Rusty25 11-Oct-23 9:53am    
Great thank you. That has return the data, with autogenerated columns, I now need to make the cells a clickable cell where there is a value. When click on the cell I need to get the value of the column header and value of the row name, to then open a new page.
Is this possible ?
Richard MacCutchan 11-Oct-23 11:06am    
Try the DataGridView.CellClick Event (System.Windows.Forms) | Microsoft Learn[^]. There is lots of information available, so if you want to use the DataGridView control, I suggest you study the documentation.
Rusty25 12-Oct-23 11:16am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900