E
et
How can I refresh a datagrid, or more precisely, insert a new row with a new
index # and reorder the remaining rows. In ItemDataBound, if the value of
the county column is different than the county in the previous row, I insert
a new row with the County name. Get the current Index
(e.Item.DataSetIndex), create the DataItem, set the new DataItem with a new
index, Create a TableCell. set the value of the TableCell to the new county,
add the control to the new index. The new row is created just fine, but
it's not displayed in the correct place. It inserts the first row just
fine, but then the next row it inserts is 2 rows off, the next inserted row
is 3 rows off, etc. If I add 2 to the item count instead of one, then the
first row is in the wrong place. I know I'm missing something! Thanks for
your help.
Dim intItemCount As Integer
strNewCounty = e.Item.Cells(2).Text
strPerson = e.Item.Cells(1).Text
If strNewCounty <> strPreviousCounty Then
Dim intNewIndex As Integer = e.Item.DataSetIndex
Dim dgItem As DataGridItem
dgItem = New DataGridItem(intNewIndex, intNewIndex + 1,
ListItemType.Item)
Dim dgCell As TableCell
dgCell = New TableCell
dgCell.ColumnSpan = 10
dgItem.Cells.Add(dgCell)
dgCell.Text = strNewCounty
dgDrillers.Controls(0).Controls.AddAt(intNewIndex + intItemCount,
dgItem)
strPreviousCounty = strNewCounty
intItemCount = intItemCount + 1
End If
index # and reorder the remaining rows. In ItemDataBound, if the value of
the county column is different than the county in the previous row, I insert
a new row with the County name. Get the current Index
(e.Item.DataSetIndex), create the DataItem, set the new DataItem with a new
index, Create a TableCell. set the value of the TableCell to the new county,
add the control to the new index. The new row is created just fine, but
it's not displayed in the correct place. It inserts the first row just
fine, but then the next row it inserts is 2 rows off, the next inserted row
is 3 rows off, etc. If I add 2 to the item count instead of one, then the
first row is in the wrong place. I know I'm missing something! Thanks for
your help.
Dim intItemCount As Integer
strNewCounty = e.Item.Cells(2).Text
strPerson = e.Item.Cells(1).Text
If strNewCounty <> strPreviousCounty Then
Dim intNewIndex As Integer = e.Item.DataSetIndex
Dim dgItem As DataGridItem
dgItem = New DataGridItem(intNewIndex, intNewIndex + 1,
ListItemType.Item)
Dim dgCell As TableCell
dgCell = New TableCell
dgCell.ColumnSpan = 10
dgItem.Cells.Add(dgCell)
dgCell.Text = strNewCounty
dgDrillers.Controls(0).Controls.AddAt(intNewIndex + intItemCount,
dgItem)
strPreviousCounty = strNewCounty
intItemCount = intItemCount + 1
End If