

<asp:DataGrid AllowPaging="True" id="ThumbsGrid" runat="server" BorderStyle="none" BorderWidth="0" CellSpacing="1" CellPadding="5" ShowHeader="False" Width="98%" OnItemDataBound="onRowBound"></asp:DataGrid>
DataTable t = new DataTable();
DataRow dr;
int picPerRow = 3;//比如显示3列数据
for(int a = 0; a != picPerRow; a++)//为索引表创建列
{
t.Columns.Add(new DataColumn(a.ToString(), typeof(string)));
}
float frows = contentDataTable.Rows.Count / picPerRow;
int num_rows = (int)Math.Ceiling(frows);//算出一共几行
for(int b = 0; b != num_rows ; b++)
{
dr = t.NewRow();
for(int a = 0; a != picPerRow; a++)
{
int curr = (b * picPerRow) + a;
dr[a] = curr.ToString();
}
t.Rows.Add(dr);
}
ThumbsGrid.DataSource = new DataView(t);
ThumbsGrid.DataBind();
protected void onRowBound(object sender, DataGridItemEventArgs e)
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
for(int a = 0; a != e.Item.Cells.Count; a++)
{
ReplaceCellContent(e.Item.Cells[a]);
}
}
private void ReplaceCellContent(TableCell i_c)
{
i_c.Text = "";//如果index超出了原表的数据条数,往往出现在最后一行。
}
else
{
}