Click to See Complete Forum and Search --> : Change DataGrid Layout


virlinz
May 14th, 2005, 05:42 AM
Hi,
Normally when we display a table from database by using a datagrid our table will have many columns according to the number of columns in the original table.

I'd like to set the datagrid to display the content of a database table in two columns only: one for the column name and the other one is for the content of each columns.. For example I want to display these details from a table in a datagrid:
Title:ASP.NET
Author: virlinz
Published by:virlinz inc

where Title, Author, Published by are the column names and ASP.NET, virlinz and virlinz inc are the content of the columns. I'd like the column names to be on one side and the contents to be on the other side.

For a real world example, the Friendster website has this kind of layout when viewing a friend's profile.

My question is how to change the datagrid layout? Is it by changing the property of the datagrid or should I create a custom datagrid? I'm a newbie in ASP.NET. Any suggestions are greatly appreciated.

Thanks in advance!

cmiskow
May 14th, 2005, 04:13 PM
So you want to display just one record from a database table? The datagrid is not for everything. For the layout you want, you could simply add labels to the form and populate the labels in the code-behind using the data source.

If you want to display multiple records in this format, you can use a repeater control with the labels.

You just must remember that the datagrid is not the right tool for every job, and learn to use the wide array of tools ASP.NET gives you.

virlinz
May 14th, 2005, 09:19 PM
Thanks very much! Never thought of doing other ways. I came across a lot of examples in datagrid, somehow it set my mind not to think out of the box. Thanks for your guidance :)