Item Data Bound Problem
Hi All,
I have a Sub to handle ItemDataBound in a DataGrid. The sub totals certain columns in the data grid to display in the footer. It also formats certain columns for Item and AlternatingItem. The problem I'm having is in the formatting the Item and AlternatingItem section. You can see in the code that all I'm trying to do is to center the data in those columns.
The problem is that it works on every row except the first one. It will not go into the For loop on the first pass. Also, in debugging the sub, on the first pass the value for grdIneventory.Items.Count = 0, so it doesn't run the For loop.
How can I resolve this problem?
Thank you for your response. Much appreciated.
Richard
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim i As Integer = 0
Dim n As Integer
'Will not go into this loop on the first pass.
For i = 0 To grdInventory.Items.Count - 1
For n = 4 To grdInventory.Items.Item(i).Cells.Count - 1
e.Item.Cells(n).Attributes.Add("align", "center")
Next
Next
ElseIf e.Item.ItemType = ListItemType.Footer Then
Dim i As Integer
Dim n As Integer
Dim y As Integer
For i = 0 To grdInventory.Items.Count - 1
n = grdInventory.Items.Item(i).Cells.Count - 1
Next
Dim x(n) As Integer
For i = 0 To grdInventory.Items.Count - 1
For n = 4 To grdInventory.Items.Item(i).Cells.Count - 1
x(n) += CInt(grdInventory.Items.Item(i).Cells(n).Text)
e.Item.Cells(n).Text = Format(x(n), "##,###")
e.Item.Cells(n).Attributes.Add("align", "center")
If Len(e.Item.Cells(n).Text) = 0 Then
e.Item.Cells(n).Text = "0"
End If
Next
Next
For i = 0 To UBound(x)
y += x(i)
Next
e.Item.Cells(0).Text = "Grand Total"
e.Item.Cells(0).Attributes.Add("align", "right")
e.Item.Cells(1).Text = Format(y, "##,###")
e.Item.Cells(2).Text = "Sub Totals"
e.Item.Cells(2).Attributes.Add("align", "right")
End If
|