2012-06-30 57 views

回答

2

你可能有一个更容易的时间,如果你能逃脱比一个DataList以外的控制。例如,你可以使用这样的Table服务器控件:

<asp:Table ID="tblGrouped" runat="server"></asp:Table>

然后在代码:

protected void LoadData() { 
    var items = MyDataSource.GetMyItems(); 

    TableRow tr = null; 
    TableCell tc = null; 

    for (int i = 0; i < items.Count; i++) { 
     if (i % 12 == 0) { 
      tr = new TableRow(); 
      tc = new TableCell(); 
      tc.Text = items[i].MyProperty; 
      tr.Cells.Add(tc); 
      tblGrouped.Rows.Add(tr); 
     } else if (i % 4 == 0) { 
      tc = new TableCell(); 
      tc.Text = items[i].MyProperty; 
      tr.Cells.Add(tc); 
     } else { 
      tc.Text += "<br />" + items[i].MyProperty; 
     } 
    } 
} 
相关问题