format data in grid

G

Guest

I'm pulling data out of an oracle db and populating a datagrid such as this

cars doors Cylinders
chevy 4 6
ford 2 8

how can i make it such as

cars chevy ford
cylinder 6 8
doors 4 2

if i can do this in either a datagrid or another way that would work
thx
 
M

Martin Marinov

You have to use DataList control instead of DataGrid control
DataList control has a property RepeatDirection that will show your data in
the way you want by setting it to Horizontal

Regards
Martin
 
D

David Lozzi

Hey,

if you find a solution, please make sure it is posted here, I am looking for
the exact same thing!

thanks,
 
D

David Lozzi

I don't think this is what we're looking for, or is it.... Lemme see if I can clear this up a little. This is how a DataGrid displays a table's data now:

ID UserName Password Security
1 David dave 10 Edit
2 John doe 10 Edit
3 Mary smith 5 Edit

Correct me if i'm wrong, but we are looking for the datagrid to do the following:

ID 1 2 3
Username David John Mary
Password dave doe smith
Security 10 10 5
Edit Edit Edit


Actually, its like a Pivot table? Maybe have a stored procedure handle the returning values as a pivot table? Would it still be editable?

THANKS!
 
M

Martin Marinov

ok, i've got your point and found a previous code that i wrote for inverting
rows and columns

DataTable dt = (DataTable) dataGrid1.DataSource;
DataTable dt_dest = new DataTable();

dt_dest.Columns.Add ( dt.Columns[0].ColumnName );
for ( int i=0; i < dt.Rows.Count; i++ )
{
dt_dest.Columns.Add ( dt.Rows[0].ToString() );
}

for ( int i=1; i < dt.Columns.Count; i++ )
{
DataRow dr = dt_dest.NewRow();
dr[0] = dt.Columns.ColumnName;
for ( int r=0; r < dt.Rows.Count; r++ )
{
dr[r+1] = dt.Rows[r];
}
dt_dest.Rows.Add ( dr );
}

DataList.DataSource = dt_dest;

Hope This Helps
Regards
Martin

I don't think this is what we're looking for, or is it.... Lemme see if I
can clear this up a little. This is how a DataGrid displays a table's data
now:

ID UserName Password Security
1 David dave 10 Edit
2 John doe 10 Edit
3 Mary smith 5 Edit

Correct me if i'm wrong, but we are looking for the datagrid to do the
following:

ID 1 2 3
Username David John Mary
Password dave doe smith
Security 10 10 5
Edit Edit Edit


Actually, its like a Pivot table? Maybe have a stored procedure handle the
returning values as a pivot table? Would it still be editable?

THANKS!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top