8

By default each row of a Gridview maps to each row in a datatable or dataset attached to its datasource. But what if I want to display these rows in multiple columns. For example if it has 10 rows, 5 rows each should be displayed in 2 columns side by side. Also can I do this with the Infragistics grid. Is this possible?

Malik Daud Ahmad Khokhar
  • 13,470
  • 24
  • 79
  • 81

3 Answers3

14

You can use a DataList control instead. It has a RepeatColumns property that you can define the number of columns you want to display.

In .NET Framework 3.5, there is an even better solution, the ListView control. You can find further information about how to use the ListView control here.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Serhat Ozgel
  • 23,496
  • 29
  • 102
  • 138
  • if you dont have ListView available and don't want to use tables you can use DataList with RepeatLayout attribute set to flow which returns data in span pairs depending on how many columns you chose. Then position the spans with CSS (either float or display inline-block). – Dan Jul 08 '09 at 20:08
1

If this is a pure coding exercise, then bind to the RowDataBound event of the Gridview. That way, you can do:

e.Row.Cells(2).Text = e.Row.Cells(1).Text

This would place the text from column 1 in column 2 after it has been pulled from the database. You can also dynamically create columns using a similar method.

Re-reading, I think I misunderstand your problem though.

BenB
  • 10,300
  • 7
  • 32
  • 30
0

Can't you just put two identical bound columns one after the other?

Charles Graham
  • 24,293
  • 14
  • 43
  • 56