I created a function to handle the "grouping":
Private Sub GroupHeader(ByVal Item As
System.Web.UI.WebControls.DataGridItem)
Dim tc As TableCell = New TableCell
tc.ColumnSpan = "4"
tc.Text = Item.Cells(3).Text & "[" & Item.ItemIndex & "]"
tc.ForeColor = System.Drawing.Color.White
tc.BackColor = System.Drawing.Color.Firebrick
Dim dgi As DataGridItem
If Item.ItemType = ListItemType.Item Then
dgi = New DataGridItem(2, 0, ListItemType.Item)
ElseIf Item.ItemType = ListItemType.AlternatingItem Then
dgi = New DataGridItem(2, 0, ListItemType.AlternatingItem)
End If
dgi.Cells.Add(tc)
DataGrid1.Controls(0).Controls.AddAt(2, dgi)
End Sub
I call this function in the ItemDataBound event if the itemtype is an
alternatingitem or an Item
Unfortunately, the new rows don't show up where I'd expect.
Can anyone explain what the first two arguments of the DataGridItem
constructor really mean? Also, if I add a row, does that change the
ItemIndex of the bound Item?
Thanks,
Craig