Sometimes I want to implement similar to the following picture, the second image:
We may first think of Datalist, in fact, Datalist We set:
<
ASP: DATALIST
id
= "DataList1"
Runat
= "Server"
Repeatcolumns
= "10"
>
<
ItemTemplate
>
<%
# DataBinder.eval (Container.DataItem, "Test")
%>
ItemTemplate
>
ASP: DATALIST
>
As shown in the above figure, it is not possible to obtain the desired longitudinal display of a certain row. In fact, it can be changed to the data source. For example, we have established such test data sources:
DataTable DT
=
New
DataTable (); Datacolumn DC
=
New
Datacolumn (
"
Test
"
, TYPE.GETTYPE
"
System.string
"
)); DT.COLUMNS.ADD (DC);
for
(
int
i
=
1
i
<=
54
i
)
{DATAROW DR = DT.NEWROW (); DR ["Test"] = "Test" i; Dt.Rows.Add (DR);}
There are 54 lines of data in the data table, we want it to display 8 lines one column, which is divided into 7 columns, reaching the effect of the above figure, write a method for conversion.
Private
DataTable Makedata (DataTable DT,
int
isize,
int
iColumnid
{Int itmp = dt.rows.count% isize; int icolumn; if (itmp == 0) iColumn = dt.rows.count / isize; else iColumn = dt.rows.count / isize 1; DataTable newdt = new dataable (); For (int I = 0; i THIS .DataGrid1.datasource = Makedata (DT, 8 , 0 ); THIS .DataGrid1.databind (); Here only explains the meaning of the three parameters of this method: The first parameter passes a original data table into the second parameter indicates how many lines of the third parameter is shown in this field. Field, the data table here is only 1 column, so write 0