Most efficient way to display a DataGrid with horizontal columns.

Posted on 2005-03-10
Medium Priority
Last Modified: 2008-03-03
I'm looking for a solution that is as elegant as the DataGrid, but allows me to display columns horizontally.  I want to be able to take a query like:
"SELECT Name, Address, PhoneNumber FROM myTable WHERE id = 1"

...and display this table:

Name:                 John Doe
Address:              123 Eisenhower Rd.
PhoneNumber:      555-1212

Normally, the DataGrid would display the column headers at the top instead of the left, like so:

Name           Address                     PhoneNumber
John Doe      123 Eisenhower Rd.    555-1212

Is there an elegant way to do this without using a repeater or something similar?  I have several dynamic recordsets, so I don't want to specify the column headers.  I just want it to take the record set, bind to the DataGrid, and AutoGenerateColumns on the left instead of the top.  A special server control, perhaps?  I know I could create a asp:Table and dynamically create the columns and values, but I was hoping for something simpler.
Question by:hendridm
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 33

Expert Comment

ID: 13511467
This is going to be impossible with the datagrid, the whole concept of this control is that each datagrid row is mapped to each row in the datasource.  What you could do is "rotate" the result set, and bind it rotated, that may work.  You'll have to scrap any concept of headers/footer that the datagrid has, but it may work for you.  Other than that, you probably can use the asp:table object, and add rows dynamically.  It's just a very weird way to display data if you ask me...  Are you just displaying one row of the datasource or many rows?.  In asp.net 2.0 they are coming out with a "detailsview" control, meant to display one item of a datasource.
LVL 33

Accepted Solution

raterus earned 2000 total points
ID: 13511490

Author Comment

ID: 13511726
Perfect!  Thanks!

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question