1

For example in my database there are 96 rows and what I want to happen is to group rows by four(the resulting table will have 3 columns with 8 rows). ex

enter image description here

Randel Ramirez
  • 3,671
  • 20
  • 49
  • 63

1 Answers1

2

You might have a much easier time if you can get away with a control other than a DataList. For instance, you could use a Table server control like this:

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

And then in code:

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;
        }
    }
}
hmqcnoesy
  • 4,165
  • 3
  • 31
  • 47