在Asp.net Gridview中显示多列中的行

时间:2022-01-01 21:01:48

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?

默认情况下,Gridview的每一行都映射到附加到其数据源的数据表或数据集中的每一行。但是,如果我想在多列中显示这些行,该怎么办呢?例如,如果它有10行,则每行5行应并排显示在2列中。我也可以使用Infragistics网格执行此操作。这可能吗?

3 个解决方案

#1


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.

您可以使用DataList控件。它具有RepeatColumns属性,您可以定义要显示的列数。

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.

在.NET Framework 3.5中,有一个更好的解决方案,即ListView控件。您可以在此处找到有关如何使用ListView控件的更多信息。

#2


1  

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

如果这是纯编码练习,则绑定到Gridview的RowDataBound事件。这样,你可以这样做:

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.

这将在从数据库中提取后,将第1列中的文本放在第2列中。您还可以使用类似的方法动态创建列。

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

重新阅读,我想我误解了你的问题。

#3


0  

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

难道你不能一个接一个地放两个相同的绑定列吗?

#1


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.

您可以使用DataList控件。它具有RepeatColumns属性,您可以定义要显示的列数。

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.

在.NET Framework 3.5中,有一个更好的解决方案,即ListView控件。您可以在此处找到有关如何使用ListView控件的更多信息。

#2


1  

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

如果这是纯编码练习,则绑定到Gridview的RowDataBound事件。这样,你可以这样做:

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.

这将在从数据库中提取后,将第1列中的文本放在第2列中。您还可以使用类似的方法动态创建列。

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

重新阅读,我想我误解了你的问题。

#3


0  

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

难道你不能一个接一个地放两个相同的绑定列吗?